Possible Duplicate:
Highlight a word with jQuery
I want to highlight certain words in html <body> tag, but I want to avoid highlighting those which are within <a> tag. How can this be done? By highlight I mean, underlining and making word bold.
For e.g I have this html content
<body>
<p>
This is sample text for the purpose of highlighting searched text. Please visit <a href="javascript:void(0)">www.sampleSite.com</a>
</p>
</body>
Now when I search for the word “sample”, I would not want to highlight the word sample contained within that anchor tag.
1. jQuery plugin to do highlighting:
2. CSS to style a
spanelement with a singlehighlightclass3. jQuery code to run after you have included the plugin & style:
OR as suggested by @Nick C. in the comments
Here is a demo
The plugin is smart enough not to replace the element’s attributes, or text inside elements such as
aelement…