Javascript examples for DOM:Element parentNode
The parentNode property returns the parent node as a Node object.
document itself is the parent node of the HTML element, HEAD and BODY are child nodes of the HTML element.
This property is read-only.
A Node object, representing the parent node of a node, or null if the node has no parent
The following code shows how to get the node name of the parent node of a <li> element:
<!DOCTYPE html> <html> <body> <p>Example list:</p> <ul> <li id="myLI">Coffee</li> <li>B</li> </ul>//from w w w. ja v a 2 s.com <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myLI").parentNode.nodeName; document.getElementById("demo").innerHTML = x; } </script> </body> </html>