Javascript Reference - HTML DOM parentNode Property








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.

Browser Support

parentNode Yes Yes Yes Yes Yes

Syntax

var v = node.parentNode

Return Value

The parent-node of a node as a Node object.





Example

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: