Skip to content
Related Articles

Related Articles

Improve Article

D3.js node.parent Property

  • Last Updated : 23 Sep, 2020

The D3.js node.parent property returns a reference to the parent node (null for the root node)

Syntax:

node.parent

Return Value: This property returns a reference to the parent node (null for the root node)

Example 1: In this example, this method will return null due to root node. 

HTML




<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
  
    <script src=
    </script>
</head>
  
<body>
    <script>
        var data = {"name":"GFG1"}
  
        var root = d3.hierarchy(data);
  
        console.log(root.parent);
    </script>
</body>
  
</html>

Output:



Example 2:

HTML




<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
  
    <script src=
    </script>
</head>
  
<body>
    <script>
        var data = {
            "name":"GeeksforGeeks", 
            "about":"Computer Science Portal",
            "children":[{"name":"GFG"}]
        }
        var root = d3.hierarchy(data);
        console.log(root.children[0].parent.data);
    </script>
</body>
  
</html>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :