您正位於 MDN Web Docs 的可編輯版本

以 MDN Web Docs 使用者身分檢視: https://developer.mozilla.org/zh-TW/docs/Web/API/ParentNode

翻譯不完整。請協助 翻譯此英文文件

ParentNode 介面定義了可以擁有子節點之 Node 物件的方法。

ParentNode 是一個原始的介面,且不能以此建立物件實體。ElementDocument 及 DocumentFragment 物件皆實作了 ParentNode

屬性

ParentNode.children Read only
該屬性會返回一個 HTMLCollection 實例,包括 ParentNode的所有子元素節點,需要特別注意的是:該屬性為唯讀
ParentNode.firstElementChild Read only
該屬性會返回 ParentNode的第一個子元素 ,如果該節點沒有子節點則返回null
ParentNode.lastElementChild Read only
該屬性會返回 ParentNode的最後一個子元素 ,如果該節點沒有子節點則返回null
ParentNode.childElementCount Read only
該屬性會返回一個無符號長整數 ,該值表示了該節點的子節點數量。

方法

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 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!
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 (25) No support 16.0 No support
append() and prepend() 54.0 49 (49) (Yes) 39 No support
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 (Yes) (Yes) 25.0 (25) No support 16.0 No support (Yes)
append() and prepend() 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 nodes as part of the results.

參見

文件標籤與貢獻者

最近更新: ianchen0119,