Jquery wrap found line inside span?
1 answer
Use a :contains()
selector to find a word New
in each <h3>
, then use .html()
with a callback String.replace()
to apply <span>
:
$('h3:contains(New)').html(function() {
return $(this).html().replace('New', '<span class="red">New</span>');
});
It turns
<h3>New stuff</h3>
in
<h3><span class="red">New</span> stuff</h3>
+4
source to share