Copyright © tutorialspoint.com
This method checks if element is a descendant of ancestor.
As Element.descendantOf internally applies $() to ancestor, it accepts indifferently an element or an element's id as its second argument.
element.descendantOf(ancestor); |
<html> <head> <title>Prototype examples</title> <script type="text/javascript" src="/javascript/prototype.js"> </script> <script> function isDescendant(){ var father = $('father'); var kid = $('kid'); // This is correct relationship and will be printed if( kid.descendantOf(father) ){ alert( "Kid is descendant of father" ); } // This is wrong relationship and will not be printed if( father.descendantOf(kid) ){ alert( "Father is descendant of kid" ); } } </script> </head> <body> <p>Click isDescendant button to see the result.</p> <div id="grandfather"> <div id="father"> <div id="kid"></div> </div> </div> <br /> <input type="button" value="isDescendant" onclick="isDescendant();"/> </body> </html> |
To understand it in better way you can Try it yourself.
Copyright © tutorialspoint.com