Here the whole text inside the div get\'s red color. but I need only the \"bar\" word color to be changed
You can use this way :
$(document).ready(function(){ // $("#foo:contains('bar')").css('color','red'); var text = 'bar' ; var context = $("#foo").html(); $("#foo").html(context.replace(text,''+text+'')); });