jQuery hasDescendant vs hasAncestor - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:jQuery Method Example

Description

jQuery hasDescendant vs hasAncestor

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.6.4.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*w w  w. j  a  v a 2  s  . c o  m*/
var a = $('#a'),
    b = $('#b');
if (a.has(b).length) {
    console.log('b is inside a');
} else {
    console.log('b is NOT inside a')
}
    });

      </script> 
 </head> 
 <body> 
  <div id="a"> 
   <div id="b"> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials