W3cubDocs

/DOM

ParentNode

The ParentNode mixin contains methods and properties that are common to all types of Node objects that can have children. It's implemented by Element, Document, and DocumentFragment 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 containing all of the Element objects that are children of this ParentNode, omitting all of its non-element nodes.
ParentNode.firstElementChild 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 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()
Inserts a set of Node objects or DOMString objects after the last child of the ParentNode. DOMString objects are inserted as equivalent Text nodes.
ParentNode.prepend()
Inserts a set of Node objects or DOMString objects before the first child of the ParentNode. DOMString objects are inserted as equivalent Text nodes.
ParentNode.querySelector()
Returns the first Element with the current element as root that matches the specified group of selectors.
ParentNode.querySelectorAll()
Returns a NodeList 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, ParentNode.lastElementChild, and ParentNode.childElementCount properties are now defined on the latter. Added the ParentNode.children property, and the ParentNode.querySelector(), ParentNode.querySelectorAll(), ParentNode.append(), and ParentNode.prepend() 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 compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 1 Yes 3.5 9 10 4
Support on Document and DocumentFragment 29 ? 25 No 16 No
childElementCount 1 Yes 3.5 9 10 4
children 1 Yes 3.5 9
9
Internet Explorer 6, 7 and 8 supported it, but erroneously includes Comment nodes.
10 4
firstElementChild 1 ? 3.5 9 10 4
lastElementChild 1 ? 3.5 9 10 4
append 54 17 49 No 39 10
prepend 54 17 49 No 39 10
querySelectorAll 1 Yes 3.5 9
9
Internet Explorer 8 only supported CSS2 selectors.
10 3.2
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support Yes Yes Yes 4 Yes Yes Yes
Support on Document and DocumentFragment Yes Yes ? ? ? No Yes
childElementCount Yes Yes Yes 4 Yes Yes Yes
children Yes Yes ? 4 ? 10 Yes
firstElementChild Yes Yes ? 4 Yes Yes Yes
lastElementChild Yes Yes ? 4 Yes Yes Yes
append 54 54 17 49 39 10.2 6.0
prepend 54 54 ? 49 39 10 6.0
querySelectorAll Yes Yes ? Yes 10 3.2 Yes

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ParentNode