contains selector in jQuery with example

  1. Contains selector returns elements that contains text matching the specified text.
  2. This selector can be used when we need to select elements based on text.

Example 1 :

    <title>contains Selector</title>
    <script type="text/javascript" src=""> </script>
    <script type="text/javascript">
    <div>This is div1 element.</div>
    <div>This is div2 element.</div>
    <div>This is div3 element.</div>
    <button id="myButton" style="margin-left:50px;">Click Me</button>
    <button onclick="location.reload()">Reset</button>

Demo :

 In the above example, we have used contains selector. Contains selector selects elements that has text matching the specified text. In the above example the contains selector selects Div2 as its content matches the specified text.


Post a Comment