You are here: Reference > JavaScript > client-side > HTML DOM > properties > parentElement

parentElement property

Browser support:
Returns the parent element of the object in the DOM hierarchy.
Use the cross-browser parentNode property instead.

Syntax:

object.parentElement;
You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

Retrieves a reference to the parent object or null for the root element.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the parentElement property:
<head>
    <script type="text/javascript">
        function GetParent (elem) {
            var parentElem = elem.parentElement;
            if (!parentElem) {
                parentElem = elem.parentNode;
            }
            alert ("The id of the parent element: " + parentElem.id);
        }
    </script>
</head>
<body>
    <div id="myDiv" style="background:green;">
        The contents of the division.
        <button onclick="GetParent (this)">Get parent element!</button>
    </div>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content