Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Static text highlighting -- can it be done?

Reply
Thread Tools

Static text highlighting -- can it be done?

 
 
bryan
Guest
Posts: n/a
 
      01-06-2007
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.

 
Reply With Quote
 
 
 
 
pcx99
Guest
Posts: n/a
 
      01-06-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Highlighting text with jpg background. Ed HTML 1 05-16-2007 03:14 PM
Highlighting part of the text in a text box Aria Javascript 3 10-13-2005 12:30 PM
Highlighting text JemPower ASP .Net 1 11-02-2003 04:34 PM
input text highlighting problem Xavier Bourguignon HTML 7 10-30-2003 10:01 AM
Code Text Highlighting Question Alan Cantor ASP .Net 0 10-07-2003 08:08 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57