PDA

View Full Version : highlighting text matches


MRB
12-31-2002, 12:43 PM
Hi,

can anyone please help with the following...

Id like to search thro the text of a page and change the color (or preferably STYLE) of ALL words or part words that matched a certain text string, lets say"my text".

So that if "my text" appeared in the document more than once, every occurence would appear in a different colour (or style).

I understand the principle here but dont know the syntax, I think that by looping thro' 'document.all' I can change the style of a particular element, but how could I do this with a peice of text?

many thanks to anyone who can give me any pointers.

Roelf
12-31-2002, 01:04 PM
read this: http://www.codingforums.com/showthread.php?s=&threadid=6036

MRB
12-31-2002, 01:09 PM
Thanks Roelf,

much appreciated :)

MRB

ca_redwards
12-31-2002, 05:09 PM
javascript:FD983r={x:function(){var r,i,s=document.selection.createRange().text;if(!s)s=prompt('Find:','');if(s){r=document.body.createT extRange();for(i=0;r.findText(s);i++){r.execCommand('BackColor','','green');r.collapse(false)};alert (i)}}};FD983r.x()