Javascript examples for DOM:Element contains
The contains() method returns a Boolean value indicating whether a node is a descendant of another node.
Parameter | Description |
---|---|
node | Required. Specifies the node that may be contained by another node |
A Boolean, indicating whether a node is a descendant of a specified node:
The following code shows how to Find out if a <span> element is a descendant of a <div> element:
<!DOCTYPE html> <html> <head> <style> #myDIV {// ww w . j a va 2 s .com border: 1px solid black; } </style> </head> <body> <div id="myDIV"> <p>p element inside div, <span id="mySPAN"><b>span</b></span></p> </div> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var span = document.getElementById("mySPAN"); var div = document.getElementById("myDIV").contains(span); document.getElementById("demo").innerHTML = div; } </script> </body> </html>