JQuery Selector Contains

From CoderLearner
Jump to: navigation, search

Description

Match elements that its text matches against a given string.

Syntax

$(":contains")

Example 1

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Select</title>
      <script 
         type="text/javascript" 
         src="/lib/jquery-1.7.2.min.js">				 
      </script>
      <style>
         .mark {
            background-color:green;
         }
      </style>
      <script>
         $().ready(function() {
            $('li:contains("21")').addClass('mark').append('--');
           
         });
      </script>
   </head>
   <body> 
      <div id="top2">
         <ul>
            <li>11</li>
            <li>21</li>
            <li>20</li>
            <li>21</li>
            <li>20</li>
         </ul>
      </div>
   </body>
</html>

Try It