Harry
Harry

Reputation: 489

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 there 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?

Upvotes: 0

Views: 389

Answers (1)

Kai
Kai

Reputation: 2987

<div id='div1'>
stack stack
<div>

$('#div1').html($('#div1').text().replace('stack','<span style="background-color:blue">stack</span>'));

Upvotes: 1

Related Questions