Skip to content
Related Articles

Related Articles

HTML | DOM parentNode Property
  • Last Updated : 26 Jul, 2019

The parentNode property is used to return the parent node of the specified node as Node object. It is a read-only property.



Return value: This property returns a parent element of the specified node or null if the current node has no parent element.


<!DOCTYPE html>
      DOM parentNode Property
<body onload="start ()" style="text-align: center">
    <h1 style="color:green">
        DOM parentNode Property
    <button onclick="geek ()">Click me!</button>
    <div id="container">
        var Text = null;
        // function to call on body load
        function start() {
            // creating a span element
            Text = document.createElement("span");
   = "green";
            Text.innerHTML = "GeeksforGeeks";
        // check function
        function geek() {
            var container = 
            // checking if parent node of Text 
            // matches with that of var container 
            if (Text.parentNode === container) {
            } else {

Before clicking on the button:
After clicking on the button:
Click the button again to hide the text.

Supported Browsers: The browser supported by parentNode property are listed below:

  • Google Chrome 1.0
  • Internet Explorer
  • Firefox 1.0
  • Opera
  • Safari

My Personal Notes arrow_drop_up
Recommended Articles
Page :