ParentNode
混合了所有(拥有子元素的) Node
对象包含的共有方法和属性。
ParentNode
是一个原始接口,不能够创建这种类型的对象;它在 Element
、Document
和 DocumentFragment
对象上被实现。
属性
ParentNode.childElementCount
只读- 返回一个当前
ParentNode
所含有的后代数量。 ParentNode.children
只读- 返回一个包含
ParentNode
所有后代Element
对象的动态HTMLCollection
对象,忽略所有非元素子节点。 ParentNode.firstElementChild
只读- 返回父节点的第一个
Element
后代,没有时返回null
。 ParentNode.lastElementChild
只读- 返回父节点的最后一个
Element
后代,没有时返回null
。
方法
ParentNode.append()
- 在父节点
ParentNode
的最后一个后代后面插入一组Node
对象或DOMString
对象。DOMString
对象会以同等的Text
节点插入。 ParentNode.prepend()
- 在父节点
ParentNode
第一个后代前插入一组Node
对象或者DOMString
对象。DOMString
对象会以同等的Text
节点插入。 ParentNode.querySelector()
- 返回以当前元素为根元素,匹配给定选择器的第一个元素
Element
。 ParentNode.querySelectorAll()
- 返回一个
NodeList
,表示以当前元素为根元素的匹配给定选择器组的元素列表。
规范
规范 | 状态 | 备注 |
---|---|---|
DOM ParentNode |
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 ElementTraversal |
Obsolete | Added the initial definition of its properties to the ElementTraversal pure interface and used it on Element . |
浏览器兼容性
BCD tables only load in the browser
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.
参见
ChildNode
纯接口。