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.childElementCountRead only- Returns the number of children of this
ParentNodewhich are elements. ParentNode.childrenRead only- Returns a live
HTMLCollectioncontaining all of theElementobjects that are children of thisParentNode, omitting all of its non-element nodes. ParentNode.firstElementChildRead only- Returns the first node which is both a child of this
ParentNodeand is also anElement, ornullif there is none. ParentNode.lastElementChildRead only- Returns the last node which is both a child of this
ParentNodeand is anElement, ornullif there is none.
Methods
ParentNode.append()- Inserts a set of
Nodeobjects orDOMStringobjects after the last child of theParentNode.DOMStringobjects are inserted as equivalentTextnodes. ParentNode.prepend()- Inserts a set of
Nodeobjects orDOMStringobjects before the first child of theParentNode.DOMStringobjects are inserted as equivalentTextnodes. ParentNode.querySelector()- Returns the first
Elementwith the current element as root that matches the specified group of selectors. ParentNode.querySelectorAll()- Returns a
NodeListrepresenting a list of elements with the current element as root that matches the specified group of selectors. ParentNode.replaceChildren()- Replaces the existing children of a node with a specified new set of children.
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 compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
ParentNode | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 3.5 | IE Full support 9 | Opera Full support 10 | Safari Full support 4 | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
append | Chrome Full support 54 | Edge Full support 17 | Firefox Full support 49 | IE No support No | Opera Full support 39 | Safari Full support 10 | WebView Android Full support 54 | Chrome Android Full support 54 | Firefox Android Full support 49 | Opera Android Full support 41 | Safari iOS Full support 10 | Samsung Internet Android Full support 6.0 |
childElementCount | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 3.5 | IE Full support 9 | Opera Full support 10 | Safari Full support 4 | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
children | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 3.5 | IE
Full support
9
| Opera Full support 10 | Safari Full support 4 | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 10.1 | Safari iOS Full support 9 | Samsung Internet Android Full support 1.0 |
Support on Document and DocumentFragment | Chrome Full support 29 | Edge Full support ≤79 | Firefox Full support 25 | IE No support No | Opera Full support 16 | Safari No support No | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android ? | Opera Android ? | Safari iOS No support No | Samsung Internet Android Full support Yes |
firstElementChild | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 3.5 | IE Full support 9 | Opera Full support 10 | Safari Full support 4 | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
lastElementChild | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 3.5 | IE Full support 9 | Opera Full support 10 | Safari Full support 4 | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
prepend | Chrome Full support 54 | Edge Full support 17 | Firefox Full support 49 | IE No support No | Opera Full support 39 | Safari Full support 10 | WebView Android Full support 54 | Chrome Android Full support 54 | Firefox Android Full support 49 | Opera Android Full support 41 | Safari iOS Full support 10 | Samsung Internet Android Full support 6.0 |
querySelector | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 3.5 | IE
Full support
9
| Opera Full support 10 | Safari Full support 4 | WebView Android Full support ≤37 | Chrome Android Full support 18 | Firefox Android Full support Yes | Opera Android Full support 10.1 | Safari iOS Full support 3.2 | Samsung Internet Android Full support Yes |
querySelectorAll | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 3.5 | IE
Full support
9
| Opera Full support 10 | Safari Full support 4 | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support Yes | Opera Android Full support 10.1 | Safari iOS Full support 3.2 | Samsung Internet Android Full support Yes |
replaceChildren | Chrome No support No | Edge No support No | Firefox Full support 78 | IE No support No | Opera No support No | Safari Full support 14 | WebView Android No support No | Chrome Android No support No | Firefox Android No support No | Opera Android No support No | Safari iOS Full support 14 | Samsung Internet Android No support No |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.
- See implementation notes.
- See implementation notes.
See also
- The
ChildNodepure interface.
