ParentNode

The ParentNode mixin contains methods and properties that are common to all types of Node (en-US) objects that can have children. It's implemented by Element, Document, and DocumentFragment (en-US) objects.

See Locating DOM elements using selectors to learn how to use CSS selectors to find nodes or elements of interest.

Properties

ParentNode.childElementCount Read only
Returns the number of children of this ParentNode which are elements.
ParentNode.children Read only
Returns a live HTMLCollection (en-US) containing all of the Element objects that are children of this ParentNode, omitting all of its non-element nodes.
ParentNode.firstElementChild (en-US) Read only
Returns the first node which is both a child of this ParentNode and is also an Element, or null if there is none.
ParentNode.lastElementChild (en-US) Read only
Returns the last node which is both a child of this ParentNode and is an Element, or null if there is none.

Methods

ParentNode.append() (en-US) This is an experimental API that should not be used in production code.
Inserts a set of Node (en-US) objects or DOMString (en-US) objects after the last child of the ParentNode. DOMString (en-US) objects are inserted as equivalent Text (en-US) nodes.
ParentNode.prepend() (en-US) This is an experimental API that should not be used in production code.
Inserts a set of Node (en-US) objects or DOMString (en-US) objects before the first child of the ParentNode. DOMString (en-US) objects are inserted as equivalent Text (en-US) nodes.
ParentNode.querySelector() (en-US)
Returns the first Element with the current element as root that matches the specified group of selectors.
ParentNode.querySelectorAll() (en-US)
Returns a NodeList (en-US) representing a list of elements with the current element as root that matches the specified group of selectors.

Specification

Specification Status Comment
DOM
The definition of 'ParentNode' in that specification.
Living Standard Split the ElementTraversal interface into ChildNode and ParentNode. The ParentNode.firstElementChild (en-US), ParentNode.lastElementChild (en-US), and ParentNode.childElementCount properties are now defined on the latter. Added the ParentNode.children property, and the ParentNode.querySelector() (en-US), ParentNode.querySelectorAll() (en-US), ParentNode.append() (en-US), and ParentNode.prepend() (en-US) methods.
Element Traversal Specification
The definition of 'ElementTraversal' in that specification.
Obsolete Added the initial definition of its properties to the ElementTraversal pure interface and used it on Element.

Browser compatibility

No compatibility data found for api.ParentNode.
Check for problems with this page or contribute missing data to mdn/browser-compat-data.

See also