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