470,593 Members | 2,383 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,593 developers. It's quick & easy.

find start and end of highlighted text in string

I am creating a little html editor, and I want to highlight a chunk of
unformatted text, click a <buttonand put a <pand the beginning and
a </pat the end. I assume there is a DOM element relating to this,
can anybody help please ? Thanks

Feb 15 '07 #1
1 1618
charliefortune <go****@charliefortune.comwrote:
I am creating a little html editor, and I want to highlight a chunk of
unformatted text, click a <buttonand put a <pand the beginning and
a </pat the end. I assume there is a DOM element relating to this,
can anybody help please ? Thanks
Saying the highlighted text is s :
var p=document.createElement('p');
p.appendChild(document.createTextNode(s));
document.body.appendChild(dp)

or if you have an element with a given id "elt_id" wehere u want to put
your <p>blahblahblah</pit is in this case :

<same as above until last line>
document.getElementById('elt_id').appendChild(p);

that's all ;-)

obviously the selected text MUST BE well balance, that's to say behaves
as xml... (if some tags in it)

how do u get the selected text ? from javascript ?
--
Une Bévue
Feb 15 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Doug van Vianen | last post: by
2 posts views Thread by Steve Barnett | last post: by
14 posts views Thread by Gary Shell | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.