Suppose I have div's and p's in HTML and they both contain same text. I want to highlight the searched text from html paragraph only. How can I do that using jQuery ?
Like
<div>Hello</div>
<div>World</div>
<p>Hello</p>
<p>World</p>
I want to highlight the 'world' in the paragraph tag.
<p>tag, don't u want to highlight that one??var nodes = document.getElementsByTagName("p"); for (var index=0; index<nodes.length; index++) { var node = nodes[index]; if (node.innerHTML.indexOf(searchTerm) != -1) { node.style.backgroundColor = "green"; } }