tadam logo
Did you find an error in the text?
Select this with mouse and press
Ctrl + Enter
Xhtml.co.il Check Spelling
Orphus system

:contains(text)

contains selector

Description: Select all elements that contain the specified text.

jQuery(':contains(text)')

version added: 1.1.4
text
A string of text to look for. It's case sensitive.

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.

Examples

Finds all divs containing "John" and underlines them.
$("div:contains('John')").css("text-decoration", "underline");
The output of the code above will be:
Full source:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
  <script>
  $(document).ready(function(){
$("div:contains('John')").css("text-decoration", "underline");
  });
  </script>  
</head>
<body>
  <div>John Resig</div>
  <div>George Martin</div>
  <div>Malcom John Sinclair</div>
  <div>J. Ohn
</body>
</html>
Was this information helpful?
   

Comments