ParentNode
The ParentNode
mixin contains methods and properties that are common to all types of Node
(en-US) objects that can have children. It's implemented by Element
, Document
, and DocumentFragment
(en-US) 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
(en-US) containing all of theElement
objects that are children of thisParentNode
, omitting all of its non-element nodes. ParentNode.firstElementChild
(en-US) 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
(en-US) 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()
(en-US)- Inserts a set of
Node
(en-US) objects orDOMString
(en-US) objects after the last child of theParentNode
.DOMString
(en-US) objects are inserted as equivalentText
(en-US) nodes. ParentNode.prepend()
(en-US)- Inserts a set of
Node
(en-US) objects orDOMString
(en-US) objects before the first child of theParentNode
.DOMString
(en-US) objects are inserted as equivalentText
(en-US) nodes. ParentNode.querySelector()
(en-US)- Returns the first
Element
with the current element as root that matches the specified group of selectors. ParentNode.querySelectorAll()
(en-US)- Returns a
NodeList
(en-US) representing 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 (en-US), ParentNode.lastElementChild (en-US), and ParentNode.childElementCount properties are now defined on the latter. Added the ParentNode.children property, and the ParentNode.querySelector() (en-US), ParentNode.querySelectorAll() (en-US), ParentNode.append() (en-US), and ParentNode.prepend() (en-US) 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
No compatibility data found for api.ParentNode
.
Check for problems with this page or contribute missing data to mdn/browser-compat-data.
See also
- The
ChildNode
pure interface.