Easiest way to find duplicate content in string
I want to use Johann Burkard's jQuery highlight plugin to highlight a term called "stack" in a div. But the开发者_JAVA百科re are more than one "stack" strings found in the div. I need to highlight only the first instance of this string. How to avoid the duplicate string using jquery?
<div id='div1'>
stack stack
<div>
$('#div1').html($('#div1').text().replace('stack','<span style="background-color:blue">stack</span>'));
精彩评论