I’m trying to highlight all matching word inside the body but not words inside any html tag. For example the keyword given is ‘para’. Here’s the paragraph:
<p class="para"> Example of paragraph. Lorem ipsum dolor sit amet. </p>
resulting in:
<p class="para">
Example of <strong>para</strong>graph. Lorem ipsum dolor sit amet.
</p>
I know that this is possible with JavaScript’s replace() but I just don’t know much about regex.
Demo: http://jsfiddle.net/crgTU/7/
You might also consider calling something like…
…before you go finding the new highlights (to remove old highlights from the DOM).