I made a small script designed to find a string and wrap it in between. The string is stored in a variable.
HTML
<h2>I have a lot of friends.</h2> <h2>My best friend name is Mike.</h2> <h2>My best friend website is <a href="http://www.myfriendmike.com">myfriendmike.com</a>.</h2>
jQuery
var term = "friend"; var item = $("h2"); $(item).each(function() { var itemHTML = $(this).html(); var newItemHTML = itemHTML.replace(term, '<span class="highlight">' + term + '</span>'); $(this).html(newItemHTML); });
That's the whole thing: http://jsfiddle.net/97hxbyy0/
script successfully replaces friend with friend; but I want him to also replace Friend or FRIEND with a friend.
In other words, I want to do this and highlight case insensitive .
Thanks!
source share