By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,420 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,420 IT Pros & Developers. It's quick & easy.

find start and end of highlighted text in string

P: n/a
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
Share this Question
Share on Google+
1 Reply

P: n/a
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.