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.
Properties
ParentNode.childrenRead only- Returns a live
HTMLCollectioncontaining all objects of typeElementthat are children of thisParentNode. ParentNode.firstElementChildRead only- Returns the
Elementthat is the first child of thisParentNode, ornullif there is none. ParentNode.lastElementChildRead only- Returns the
Elementthat is the last child of thisParentNode, ornullif there is none. ParentNode.childElementCountRead only- Returns an
unsigned longgiving the amount of children that the object has.
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.
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. |
Recommendation | Added the initial definition of its properties to the ElementTraversal pure interface and used it on Element. |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Edge | Opera | Safari |
|---|---|---|---|---|---|---|
Basic support (on Element) |
1.0 | 3.5 (1.9.1) | 9.0 | ? | 10.0 | 4.0 |
Support on Document and DocumentFragment |
29.0 | 25 (25) | No support | ? | 16.0 | No support |
append() and prepend() |
54.0 | 49 (49) | No support | No support | 39 | No support |
| Feature | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Edge Mobile | Opera Mobile | Safari Mobile | Chrome for Mobile |
|---|---|---|---|---|---|---|---|
Basic support (on Element) |
(Yes) | 1.0 (1.9.1) | (Yes) | ? | (Yes) | (Yes) | (Yes) |
Support on Document and DocumentFragment |
(Yes) | 25.0 (25) | No support | ? | 16.0 | No support | (Yes) |
append() and prepend() |
? | 49.0 (49) | No support | ? | 39 | No support | 54.0 |
See also
- The
ChildNodepure interface.
Document Tags and Contributors
Tags:
Contributors to this page:
DomenicDenicola,
stevenwdv,
Sheppy,
Sebastianz,
jpmedley,
fscholz,
cvrebert,
MHasan,
jdfm,
kscarfone,
Localsystem,
Jeremie,
NekR,
teoli
Last updated by:
DomenicDenicola,