[Solved] Jquery – Find a word in a string and wrap it with tag
You need to do this : var txt = textDiv.replace(new RegExp(searchInput, ‘gi’), function(str) { return “<span class=”highlight”>” + str + “</span>” }); or var txt = textDiv.replace( new RegExp(searchInput, ‘gi’), “<span class=”highlight”>$&</span>”); gi -> all case insensitive matching text $(document).ready(function() { // globals var searchInput; var textDiv; $(‘.searchBtn’).click(function(event) { event.preventDefault(); // set the values of … Read more