Javascript examples for jQuery Selector:contains
The :contains() selector selects elements which contain the case sensitive string, which can be contained directly in the element as text, or in a child element.
Parameter | Description |
---|---|
text | Required. text to find |
The following code shows how to select all <p> elements containing "is":
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p:contains(is)").css("background-color", "yellow"); });//from w w w . j a va 2 s . c o m </script> </head> <body> <h1>Welcome to My Homepage</h1> <p class="test">This is a test.</p> <p>This is a paragraph.</p> <p>This is a paragraph.</p> Who is your favourite: <ul id="myList"> <li>A</li> <li>B</li> <li>C</li> </ul> </body> </html>