for example, there is following html in search results, and the aa
is the keyword:
<body>
<div>
<h2><a href="#aa">aabbcc</a></h2>
</div>
<div>
<h2><a href="#bb">aaeeedd</a></h2>
</div>
<div>
<h2><a href="#cc">vvaapp</a></h2>
</div>
</body>
I want to highlight the search keyword aa
in results and don't change other anything :
I try this:
var text = $('body').html().replace(new RegExp('aa','gim'),"<span class='highlight'>aa</span>");
$('body').html(text);
But all html were replaced, include the href '#aa'.
I think use the each()
and text()
maybe ok.
And is there better solution?