Web/API/ParentNode

From Get docs


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.
ParentNode.replaceChildren()
Replaces the existing children of a node with a specified new set of children.

Specification

Specification Status Comment
DOMThe 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 SpecificationThe 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

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
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

Experimental'

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

Notes'

Full support 9

Notes'

Notes' Internet Explorer 6, 7 and 8 supported it, but erroneously includes Comment nodes.

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

Experimental'

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

Experimental'

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

Notes'

Full support 9

Notes'

Notes' Internet Explorer 8 only supported CSS2 selectors.

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 1.0

querySelectorAll Chrome

Full support 1

Edge

Full support 12

Firefox

Full support 3.5

IE Full support 9

Notes'

Full support 9

Notes'

Notes' Internet Explorer 8 only supported CSS2 selectors.

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

Experimental'

Chrome

Full support 86

Edge

Full support 86

Firefox

Full support 78

IE

No support No

Opera

Full support 72

Safari

No support No

WebView Android

Full support 86

Chrome Android

Full support 86

Firefox Android

No support No

Opera Android

No support No

Safari iOS

No support No

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