The parentNode
property returns the parent node as a Node object.
It returns null if the the specified node does not have a parent node.
parentNode |
Yes | Yes | Yes | Yes | Yes |
var v = node.parentNode
The parent-node of a node as a Node object.
The following code shows how to get the parentNode of an <li> element.
<!DOCTYPE html>
<html>
<body>
<ul><li>A</li><li>B</li></ul>
<button onclick="myFunction()">test</button>
<script>
function myFunction()<!-- w w w .ja v a 2s.co m-->
{
var x=document.getElementById("demo");
var y=document.getElementsByTagName("LI")[0];
x.innerHTML=y.parentNode.nodeName;
}
</script>
</body>
</html>
The code above is rendered as follows: