ParentNode
ParentNode
介面定義了可以擁有子節點之 Node
物件的方法。
ParentNode
是一個原始的介面,且不能以此建立物件實體。Element
、Document
及 DocumentFragment
物件皆實作了 ParentNode
。
屬性
ParentNode.children
Experimental Read only- 該屬性會返回一個
HTMLCollection
實例,包括ParentNode
的所有子元素節點,需要特別注意的是:該屬性為唯讀
。 ParentNode.firstElementChild
Experimental Read only- 該屬性會返回
ParentNode
的第一個子元素 ,如果該節點沒有子節點則返回null
。 ParentNode.lastElementChild
(en-US) Experimental Read only- 該屬性會返回
ParentNode
的最後一個子元素 ,如果該節點沒有子節點則返回null
。 ParentNode.childElementCount
(en-US) Experimental Read only- 該屬性會返回一個
無符號長整數
,該值表示了該節點的子節點數量。
方法
ParentNode.append()
(en-US) Experimental- Inserts a set of
Node
objects orDOMString
objects after the last child of theParentNode
.DOMString
objects are inserted as equivalentText
(en-US) nodes. ParentNode.prepend()
(en-US) Experimental- Inserts a set of
Node
objects orDOMString
objects before the first child of theParentNode
.DOMString
objects are inserted as equivalentText
(en-US) 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 | Status | Comment |
---|---|---|
DOM The definition of 'ParentNode' in that specification. |
Living Standard | Added the append() and prepend() methods. |
DOM4 The definition of 'ParentNode' in that specification. |
Obsolete | 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 and the querySelector() and querySelectorAll() 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 . |
瀏覽器相容性
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help! (en-US)
Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Mobile |
---|---|---|---|---|---|---|---|
Basic support (on Element ) |
(Yes) | (Yes) | 1.0 (1.9.1) | (Yes) | (Yes) | (Yes) | (Yes) |
Support on Document and DocumentFragment
Experimental
|
(Yes) | (Yes) | 25.0 (25) | No support | 16.0 | No support | (Yes) |
append() and prepend()
Experimental
|
No support | 54.0 | 49.0 (49) | No support | 39 | No support | 54.0 |
[1] Internet Explorer 6, 7 and 8 supported it, but erroneously returns Comment
(en-US) nodes as part of the results.
參見
- The
ChildNode
pure interface.