jQuery hasDescendant vs hasAncestor - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:jQuery Method Example


jQuery hasDescendant vs hasAncestor

Demo Code

ResultView the demo in separate window

  <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')

  <div id="a"> 
   <div id="b"> 

Related Tutorials