JQuery Selector has

From CoderLearner
Jump to: navigation, search

Description

Select elements that at least contains one element matches a given selector.

Syntax

$('element:has("selector")')

$('div:has("p")')

$('span:has("id")')

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>
      <script>
         $().ready(function() {
            $('div:has("p")').css('color','red');
         });
      </script>
   </head>
   <body> 
      <div id="top1">
         <ul>
            <li>One</li>
            <li>Two</li>
            <li>Three</li>
         </ul>
      </div>
      <div>
         <p>Blue Vs. Red</p>
      </div>
   </body>
</html>

Try It