A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/dom/Node/parentNode below:

parentNode ยท WebPlatform Docs

parentNode Summary

Retrieves the parent node in the document hierarchy.

Property of dom/Nodedom/Node

Syntax

Note: This property is read-only.

var parentNode = node.parentNode;
Return Value

Returns an object of type DOM NodeDOM Node

The parent node of the node.

Examples

This example assigns the parentNode of a span object to a variable.

<script>
var oParent = document.getElementById("oSpan").parentNode;
</script>
:
<body>
<span ID="oSpan">A Span</span>
</body>

This example assigns the parentNode of a node, created with the createElement method, to a variable.

var oNode = document.createElement("B");
document.body.insertBefore(oNode);

var oParent = oNode.parentNode;

This example demonstrates the difference between parentNode and parentElement when queried on the documents root element (<html>)

<!DOCTYPE html>
<html id="root">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>parentElement/parentNode</title>
</head>

<body>
<script type="text/javascript">
var root=document.getElementById('root');
try{document.write('typeof root.parentNode:'+ typeof(root.parentNode)+'<br/>');}catch(e){alert(e);}
try{document.write('root.parentNode.tagName:'+root.parentNode.tagName+'<br/>');}catch(e){alert(e);}
try{document.write('typeof root.parentElement:'+typeof(root.parentElement)+'<br/>');}catch(e){alert(e);}
try{document.write('root.parentElement.tagName:'+root.parentElement.tagName+'<br/>');}catch(e){alert(e);}
</script>
</body>

</html>
Usage
 Use to find the parent of a node (if any).
Notes

The topmost object returns null as its parent.

Related specifications
DOM Level 3 Core
Recommendation
Attributions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4