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 theElement
objects that are children of thisParentNode
, 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 anElement
, ornull
if there is none. ParentNode.lastElementChild
Read only- Returns the last node which is both a child of this
ParentNode
and is anElement
, ornull
if there is none.
Methods
ParentNode.append()
- Inserts a set of
Node
objects orDOMString
objects after the last child of theParentNode
.DOMString
objects are inserted as equivalentText
nodes. ParentNode.prepend()
- Inserts a set of
Node
objects orDOMString
objects before the first child of theParentNode
.DOMString
objects are inserted as equivalentText
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. 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
ChildNode
pure interface.