<div>John Resig</div>
<div>George Martin</div>
<div>Malcom John Sinclair</div>
<div>J. Ohn</div>
<script>
$("div:contains('John')").css("text-decoration", "underline");
</script>
The above code will add underline to the total DIV which contains “John”.But how can i make only “John” to be underlined.
Please someone help me.
You’ll have to wrap your text in a span:
http://jsfiddle.net/GP96T/2/
As noted by @Brad Christie, you should only use this if you either know that you don’t have “John” somewhere in your attributes, or the
divs have no children.