--- title: ChildNode slug: Web/API/ChildNode translation_of: Web/API/ChildNode ---
{{APIRef("DOM")}}

childNodes 介面定義了可以擁有父節點之 {{domxref("Node")}} 物件的方法。

childNodes 是一個原始的介面,且不能以此建立物件實體。{{domxref("Element")}}、{{domxref("DocumentType")}} 及 {{domxref("CharacterData")}} 物件皆實作了 childNodes

屬性

沒有繼承或自有的屬性。

方法

沒有繼承的方法。

{{domxref("childNodes.remove()")}} {{experimental_inline}}
Removes this childNodes from the children list of its parent.
{{domxref("childNodes.before()")}} {{experimental_inline}}
Inserts a set of {{domxref("Node")}} or {{domxref("DOMString")}} objects in the children list of this childNodes's parent, just before this childNodes. {{domxref("DOMString")}} objects are inserted as equivalent {{domxref("Text")}} nodes.
{{domxref("childNodes.after()")}} {{experimental_inline}}
Inserts a set of {{domxref("Node")}} or {{domxref("DOMString")}} objects in the children list of this childNodes's parent, just after this childNodes. {{domxref("DOMString")}} objects are inserted as equivalent {{domxref("Text")}} nodes.
{{domxref("childNodes.replaceWith()")}} {{experimental_inline}}
Replaces this childNodes in the children list of its parent with a set of {{domxref("Node")}} or {{domxref("DOMString")}} objects. {{domxref("DOMString")}} objects are inserted as equivalent {{domxref("Text")}} nodes.

規範

Specification Status Comment
{{SpecName('DOM WHATWG', '#interface-childnode', 'childNodes')}} {{Spec2('DOM WHATWG')}} Split the ElementTraversal interface in {{domxref("ParentNode")}} and childNodes. previousElementSibling and nextElementSibling are now defined on the latter. The {{domxref("CharacterData")}} and {{domxref("DocumentType")}} implemented the new interfaces. Added the remove(), before(), after() and replaceWith() methods.
{{SpecName('Element Traversal', '#interface-elementTraversal', 'ElementTraversal')}} {{Spec2('Element Traversal')}} Added the initial definition of its properties to the ElementTraversal pure interface and use it on {{domxref("Element")}}.

Polyfill

External on github: childNode.js

瀏覽器相容性

{{ CompatibilityTable }}

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support (on {{domxref("Element")}}) {{CompatChrome(1.0)}} {{CompatVersionUnknown}} {{CompatGeckoDesktop(23)}} 9.0 10.0 4.0
Support on {{domxref("DocumentType")}} and {{domxref("CharacterData")}} {{experimental_inline}} {{CompatChrome(23.0)}} {{CompatNo}} {{CompatGeckoDesktop(23)}} {{CompatNo}} 16.0 {{CompatNo}}
remove(){{experimental_inline}} {{CompatChrome(29.0)}} {{CompatVersionUnknown}} {{CompatGeckoDesktop(23)}} {{CompatNo}} 16.0 {{CompatNo}}
before(), after(), and replaceWith() {{experimental_inline}} {{CompatChrome(54.0)}} {{CompatNo}} {{CompatGeckoDesktop(49)}} {{CompatNo}} {{CompatOpera(39)}} {{CompatNo}}
Feature Android Android Webview Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support (on {{domxref("Element")}}) {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatGeckoMobile(23)}} {{CompatVersionUnknown}} 10.0 {{CompatVersionUnknown}} {{CompatVersionUnknown}}
Support on {{domxref("DocumentType")}} and {{domxref("CharacterData")}} {{experimental_inline}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatNo}} {{CompatGeckoMobile(23)}} {{CompatNo}} 16.0 {{CompatNo}} {{CompatVersionUnknown}}
remove(){{experimental_inline}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatGeckoMobile(23)}} {{CompatNo}} 16.0 {{CompatNo}} {{CompatVersionUnknown}}
before(), after(), and replaceWith() {{experimental_inline}} {{CompatNo}} {{CompatChrome(54.0)}} {{CompatNo}} {{CompatGeckoMobile(49)}} {{CompatNo}} {{CompatOperaMobile(39)}} {{CompatNo}} {{CompatChrome(54.0)}}

參見