Static text highlighting -- can it be done?

B

bryan

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.
 
P

pcx99

bryan said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top