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.
ParentNode.childElementCount
Read only
ParentNode
which are elements.ParentNode.children
Read only
HTMLCollection
containing all of the Element
objects that are children of this ParentNode
, omitting all of its non-element nodes.ParentNode.firstElementChild
Read only
ParentNode
and is also an Element
, or null
if there is none.ParentNode.lastElementChild
Read only
ParentNode
and is an Element
, or null
if there is none.ParentNode.append()
Node
objects or DOMString
objects after the last child of the ParentNode
. DOMString
objects are inserted as equivalent Text
nodes.ParentNode.prepend()
Node
objects or DOMString
objects before the first child of the ParentNode
. DOMString
objects are inserted as equivalent Text
nodes.ParentNode.querySelector()
Element
with the current element as root that matches the specified group of selectors.ParentNode.querySelectorAll()
NodeList
representing a list of elements with the current element as root that matches the specified group of selectors.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 . |
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
|
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
|
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 |
ChildNode
pure interface.
© 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