开发者

Easiest way to find duplicate content in string

开发者 https://www.devze.com 2023-04-11 16:45 出处:网络
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 highligh

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>'));
0

精彩评论

暂无评论...
验证码 换一张
取 消