Luet tämän sisällön englanninkielistä versiota, koska tälle sisällölle ei ole vielä käännöstä. Auta meitä kääntämään tämä artikkeli!
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 theElement
objects that are children of thisParentNode
, 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 anElement
, ornull
if there is none. ParentNode.lastElementChild
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()
- Inserts a set of
Node
objects orDOMString
objects after the last child of theParentNode
.DOMString
objects are inserted as equivalentText
nodes. ParentNode.prepend()
- Inserts a set of
Node
objects orDOMString
objects before the first child of theParentNode
.DOMString
objects are inserted as equivalentText
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
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
ParentNode | Chrome Full support 1 | Edge Full support Yes | 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 | 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 Yes | 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 Yes | 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 ? | Safari iOS Full support 9 | Samsung Internet Android Full support Yes |
Support on Document and DocumentFragment | Chrome Full support 29 | Edge ? | 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 ? | 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 Yes | 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 | 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 |
querySelectorAll | Chrome Full support 1 | Edge Full support Yes | 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 Yes | Opera Android Full support 10.1 | Safari iOS Full support 3.2 | Samsung 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
- The
ChildNode
pure interface.