ドキュメント

Selectors/contains

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Selectors

:contains(text)

Matches elements which contain the given text.
Arguments:
textString
A string of text to look for. It's case sensitive.
Examples:

Finds all divs containing "John" and underlines them.

$("div:contains('John')").css("text-decoration", "underline");

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<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>

NameType