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.

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

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support 1Edge Full support YesFirefox Full support 3.5IE Full support 9Opera Full support 10Safari Full support 4WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
Support on Document and DocumentFragment
Experimental
Chrome Full support 29Edge ? Firefox Full support 25IE No support NoOpera Full support 16Safari No support NoWebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android ? Opera Android ? Safari iOS No support NoSamsung Internet Android Full support Yes
childElementCountChrome Full support 1Edge Full support YesFirefox Full support 3.5IE Full support 9Opera Full support 10Safari Full support 4WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
childrenChrome Full support 1Edge Full support YesFirefox Full support 3.5IE 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 10Safari Full support 4WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 4Opera Android ? Safari iOS Full support 10Samsung Internet Android Full support Yes
firstElementChildChrome Full support 1Edge ? Firefox Full support 3.5IE Full support 9Opera Full support 10Safari Full support 4WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
lastElementChildChrome Full support 1Edge ? Firefox Full support 3.5IE Full support 9Opera Full support 10Safari Full support 4WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
append
Experimental
Chrome Full support 54Edge Full support 17Firefox Full support 49IE No support NoOpera Full support 39Safari Full support 10WebView Android Full support 54Chrome Android Full support 54Edge Mobile Full support 17Firefox Android Full support 49Opera Android Full support 39Safari iOS Full support 10.2Samsung Internet Android Full support 6.0
prepend
Experimental
Chrome Full support 54Edge Full support 17Firefox Full support 49IE No support NoOpera Full support 39Safari Full support 10WebView Android Full support 54Chrome Android Full support 54Edge Mobile ? Firefox Android Full support 49Opera Android Full support 39Safari iOS Full support 10Samsung Internet Android Full support 6.0
querySelectorAllChrome Full support 1Edge Full support YesFirefox Full support 3.5IE Full support 9
Notes
Full support 9
Notes
Notes Internet Explorer 8 only supported CSS2 selectors.
Opera Full support 10Safari Full support 3.2WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support YesOpera Android Full support 10Safari iOS Full support 3.2Samsung Internet Android Full support Yes

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