ParentNode mixin 包含可以拥有子项的所有类型的 Node对象共有的方法和属性。

ParentNode 是一个原始接口,不能够创建这种类型的对象;它在 ElementDocumentDocumentFragment 对象上被实现。

属性

ParentNode.children 只读
返回一个包含父节点所有Element 类型的后代的动态html集合 HTMLCollection 
ParentNode.firstElementChild 只读
返回父节点的第一个Element后代,没有时候返回null
ParentNode.lastElementChild 只读
返回父节点的最后一个Element后代,没有时返回null
ParentNode.childElementCount 只读
返回一个无符号长整型,给出对象含有的后代数量

方法

ParentNode.append()
在父节点的最后一个后代后面插入一组 Node 对象或 DOMString 对象。DOMString 对象会以同等的 Text 节点插入
ParentNode.prepend()
在父节点第一个后代前插入一组 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.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
ParentNodeChrome 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 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 ? 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 No support NoFirefox 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 4WebView 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.

参见

文档标签和贡献者

标签: 
此页面的贡献者: RainSlide, _sollrei, xgqfrms-GitHub, AlexChao
最后编辑者: RainSlide,