:contains() Selector in JQuery



version added: 1.1.4jQuery(‘:contains(text)’)

The matching text can appear directly within the selected element, in any of that element’s descendants, or a combination thereof. As with attribute value selectors, text inside the parentheses of :contains() can be written as bare words or surrounded by quotation marks. The text must have matching case to be selected.


Finds all divs containing “John” and underlines them.

<!DOCTYPE html>
  <script src="/scripts/jquery-1.4.js"></script>
	<div>John Resig</div>

  <div>George Martin</div>
  <div>Malcom John Sinclair</div>
  <div>J. Ohn
<script>$("div:contains('John')").css("text-decoration", "underline");</script>

Leave a Reply

Your email address will not be published. Required fields are marked *