The ParentNode interface contains methods that are particular to Node objects that can have children.
ParentNode is a raw interface and no object of this type can be created; it is implemented by Element, Document, and DocumentFragment objects.
PropertiesEdit
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.
MethodsEdit
ParentNode.append()ParentNode.prepend()ParentNode.query()ParentNode.queryAll()ParentNode.querySelector()ParentNode.querySelectorAll()
SpecificationEdit
| Specification | Status | Comment |
|---|---|---|
| DOM The definition of 'ParentNode.firstElementChild' in that specification. |
Living Standard | Splitted the ElementTraversal interface in ChildNode and ParentNode. The firstElementChild, lastElementChild, and childElementCount properties are now defined on the latter.The Document and DocumentFragment implemented the new interfaces.Added the children property.Added the append() and 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 use it on Element. |
Browser compatibilityEdit
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
Basic support (on Element) |
1.0 | 3.5 (1.9.1) | 9.0 [1] | 10.0 | 4.0 |
Support on Document and DocumentFragment |
29.0 | 25.0 (25.0) | No support | 16.0 | No support |
append() and prepend() |
No support | No support | No support | No support | No support |
[1] Internet Explorer 6, 7 and 8 supported it, but erroneously returns Comment nodes as part of the results.
See alsoEdit
- The
ChildNodepure interface.