Here the whole text inside the div get\'s red color. but I need only the \"bar\" word color to be changed
You can do like this.
$(document).ready(function(){ var matchingTest = 'demo'; $("#container:contains("+matchingTest+")").each(function () { $(this).html($(this).html().replace(matchingTest, ""+matchingTest+"")); }); });
.red{ background:#eada93; }
Hello this is a demo contents.