parentNode

In this chapter you will learn:

  1. How to get the parent node in Javascript

Parent node

Each node has a parentNode property pointing to its parent.

<!DOCTYPE html><!--from j  a v  a 2s.com-->
<html>
    <body>
        <div id="div1">
            <p>Hello <b>World!</b></p>
            <ul>
                <li>List item 1</li>
                <li>List item 2</li>
                <li>List item 3</li>
            </ul>
        </div>
        <p>Hello <b>World!</b></p>
        <script type="text/javascript">
               var div = document.getElementById("div1");
               var node = div.parentNode;
               document.writeln(node);
               

        </script>
        
    </body>
</html>

Click to view the demo

Next chapter...

What you will learn in the next chapter:

  1. How to get the previous sibling and next sibling
  2. Deal with null sibling value
Home » Javascript Tutorial » DOM
Document Object Model
Node Type
nodeName and nodeValue
childNodes
parentNode
previousSibling and nextSibling
lastChild and firstChild
appendChild
insertBefore
ownerDocument
removeChild
replaceChild
Text
NodeList Length
DOM classes