Rob, My problem is that I have no way of knowing where the keyword may appear. It might be tabular data (<TD>) or in descriptive paragraph (<p>).
So if my keyword is RED, then... BEFORE <p> the red fox </p> AFTER <p>the <span>red</span> fox</p> I'll have an array of keywords as well. var arrayx["one", "two" "three"] On Feb 2, 5:57 pm, RobG <rg...@iinet.net.au> wrote: > On Feb 3, 8:01 am, paulinstl <paulsha...@gmail.com> wrote: > > > I'm looking for a way to locate keywords to help the end user out. > > > For instance, if I want to find the word "polar" then i'd like my > > function to locate it, wrap it with a span, and assign it a function. > > > so far I can locate using a content filter and classname like this... > > > $(".keyword:contains('polar')") > > > But this selects the whole element (paragraph, div, whatever) > > > how do i focus in on JUST the text? > > The most reliable method is to traverse the part of the DOM you want > to search and look at the value of text nodes. If you want to > highlight a particular character pattern, use a regular expression and > DOM methods to wrap it in a suitable element, say a span. It would > also be prudent to also put adjacent text in spans too, e.g. > > <div>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</dv> > > might become: > > <div><span>Lorem ipsum </span><span class="foo">dolor</span> > <span> sit amet, consectetur adipiscing elit.</span></dv> > > That way you can also deal with text found inside elements like B or > QUOTE if necessary. > > Other approaches such as using a regular exprssion and an element's > innerHTML property, are likely to be error prone. > > -- > Rob