이 번역은 완료되지 않았습니다. 이 문서를 번역해 주세요.

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

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support1 Yes3.59104
Support on Document and DocumentFragment29 ?25 No16 No
childElementCount1 Yes3.59104
children1 Yes3.591104
firstElementChild1 ?3.59104
lastElementChild1 ?3.59104
append541749 No3910
prepend541749 No3910
querySelectorAll1 Yes3.592103.2
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes Yes Yes4 Yes Yes Yes
Support on Document and DocumentFragment Yes Yes ? ? ? No Yes
childElementCount Yes Yes Yes4 Yes Yes Yes
children Yes Yes ?4 ?10 Yes
firstElementChild Yes Yes ?4 Yes Yes Yes
lastElementChild Yes Yes ?4 Yes Yes Yes
append545417493910.26.0
prepend5454 ?4939106.0
querySelectorAll Yes Yes ? Yes103.2 Yes

1. Internet Explorer 6, 7 and 8 supported it, but erroneously includes Comment nodes.

2. Internet Explorer 8 only supported CSS2 selectors.

See also

문서 태그 및 공헌자

이 페이지의 공헌자: ExE-Boss
최종 변경자: ExE-Boss,