bryan wrote:
I'm trying to write an application to demonstrate to a friend how to
highlight text in javascript, only problem is he wants it to be on divs
only.
So say for example you have a page, and you select some text in the div
(this is static text, not a form or anything) and you click "highlight"
is there a way to wrap style tags around that highlighted text using
javascript, without refreshing the page?
thanks.
Yes it is possible. Though it's a bit of work so I doubt if people are
going to fall all over-themselves to provide you with the code you want.
But yes -- check out...
http://www.quirksmode.org/js/selected.html for how to get the selected text.
Then look into the innerHTML reference, and then look into javascript
replace.
Basically the flow will go.
User clicks button->
Get the selected text->
Save the original division.innerHTML->
run replace on innerHTML to add your tags....
Good luck.
--
http://www.hunlock.com -- Musings in Javascript, CSS.
$FA