--- title: ParentNode slug: Web/API/ParentNode tags: - API - DOM - Finding Elements - Finding Nodes - Interface - Locating Elements - Locating Nodes - Managing Elements - Managing Nodes - Mixin - NeedsTranslation - Node - ParentNode - Reference - Selectors - TopicStub translation_of: Web/API/ParentNode ---
{{APIRef("DOM")}}

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

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

Properties

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

Methods

{{domxref("ParentNode.append()")}} {{experimental_inline}}
Inserts a set of {{domxref("Node")}} objects or {{domxref("DOMString")}} objects after the last child of the ParentNode. {{domxref("DOMString")}} objects are inserted as equivalent {{domxref("Text")}} nodes.
{{domxref("ParentNode.prepend()")}} {{experimental_inline}}
Inserts a set of {{domxref("Node")}} objects or {{domxref("DOMString")}} objects before the first child of the ParentNode. {{domxref("DOMString")}} objects are inserted as equivalent {{domxref("Text")}} nodes.
{{domxref("ParentNode.querySelector()")}}
Returns the first {{domxref("Element")}} with the current element as root that matches the specified group of selectors.
{{domxref("ParentNode.querySelectorAll()")}}
Returns a {{domxref("NodeList")}} representing a list of elements with the current element as root that matches the specified group of selectors.

Specification

Specification Status Comment
{{SpecName('DOM WHATWG', '#parentnode', 'ParentNode')}} {{Spec2('DOM WHATWG')}} Split the ElementTraversal interface into {{domxref("ChildNode")}} and {{domxref("ParentNode")}}. The {{domxref("ParentNode.firstElementChild")}}, {{domxref("ParentNode.lastElementChild")}}, and {{domxref("ParentNode.childElementCount")}} properties are now defined on the latter. Added the {{domxref("ParentNode.children")}} property, and the {{domxref("ParentNode.querySelector()")}}, {{domxref("ParentNode.querySelectorAll()")}}, {{domxref("ParentNode.append()")}}, and {{domxref("ParentNode.prepend()")}} methods.
{{SpecName('Element Traversal', '#interface-elementTraversal', 'ElementTraversal')}} {{Spec2('Element Traversal')}} Added the initial definition of its properties to the ElementTraversal pure interface and used it on {{domxref("Element")}}.

Browser compatibility

{{Compat("api.ParentNode")}}

See also