Open In App
Related Articles

HTML DOM parentNode Property

Improve Article
Save Article
Like Article

The parentNode property is used to return the parent node of the specified node as a 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. 

Example: In this example, we will use the parentNode property


<!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">
        let 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() {
           let container =
            // checking if parent node of Text
            // matches with that of var container
            if (Text.parentNode === container) {
            } else {



Click the button again to hide the text.

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

  • Google Chrome 1.0 and above
  • Edge 12 and above
  • Internet Explorer 5.5 and above
  • Firefox 1.0 and above
  • Opera 7 and above
  • Safari 1.1 and above

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 09 Jun, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials