ChildNode mixin contains methods and properties that are common to all types of 节点 objects that can have a parent. It's implemented by 元素 , DocumentType ,和 CharacterData 对象。

特性

There are neither inherited, nor specific properties.

方法

There are no inherited methods.

ChildNode.remove()
Removes this ChildNode children list of its parent.
ChildNode.before()
Inserts a set of 节点 or DOMString objects in the children list of this ChildNode 's parent, just before this ChildNode . DOMString objects are inserted as equivalent 文本 节点。
ChildNode.after()
Inserts a set of 节点 or DOMString objects in the children list of this ChildNode 's parent, just after this ChildNode . DOMString objects are inserted as equivalent 文本 节点。
ChildNode.replaceWith()
Replaces this ChildNode children list of its parent with a set of 节点 or DOMString 对象。 DOMString objects are inserted as equivalent 文本 节点。

规范

规范 状态 注释
DOM
The definition of 'ChildNode' in that specification.
实时标准 Split the ElementTraversal interface in ParentNode and ChildNode . previousElementSibling and nextElementSibling are now defined on the latter. The CharacterData and DocumentType implemented the new interfaces. Added the remove() , before() , after() and replaceWith() 方法。
Element Traversal Specification
The definition of 'ElementTraversal' in that specification.
过时 Added the initial definition of its properties to the ElementTraversal pure interface and use it on 元素 .

Polyfill

External on GitHub: childNode.js

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
ChildNode Chrome 1 Edge 12 Firefox 23 IE 9 Opera 10 Safari 4 WebView Android Yes Chrome Android Yes Firefox Android 23 Opera Android 10.1 Safari iOS Yes Samsung Internet Android Yes
after Chrome 54 Edge 17 Firefox 49 IE No Opera 39 Safari 10 WebView Android 54 Chrome Android 54 Firefox Android 49 Opera Android 41 Safari iOS 10 Samsung Internet Android 6.0
before Chrome 54 Edge 17 Firefox 49 IE No Opera 39 Safari 10 WebView Android 54 Chrome Android 54 Firefox Android 49 Opera Android 41 Safari iOS 10 Samsung Internet Android 6.0
remove Chrome 23 Edge 12 Firefox 23 IE No Opera 15 Safari 7 WebView Android ≤37 Chrome Android 25 Firefox Android 23 Opera Android 14 Safari iOS 7 Samsung Internet Android 1.5
replaceWith Chrome 54 Edge 17 Firefox 49 IE No Opera 39 Safari Yes WebView Android 54 Chrome Android 54 Firefox Android 49 Opera Android 41 Safari iOS Yes Samsung Internet Android 6.0

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

另请参阅

  • NonDocumentTypeChildNode interface
  • 元数据

    1. DOM (文档对象模型)
    2. ChildNode
    3. 方法
      1. after()
      2. before()
      3. remove()
      4. replaceWith()
    4. 实现通过:
      1. CharacterData
      2. DocumentType
      3. 元素
    5. DOM 相关页面
      1. AbortController
      2. AbortSignal
      3. AbstractRange
      4. Attr
      5. ByteString
      6. CDATASection
      7. CSSPrimitiveValue
      8. CSSValue
      9. CSSValueList
      10. CharacterData
      11. 注释
      12. CustomEvent
      13. DOMConfiguration
      14. DOMError
      15. DOMErrorHandler
      16. DOMException
      17. DOMImplementation
      18. DOMImplementationList
      19. DOMImplementationRegistry
      20. DOMImplementationSource
      21. DOMLocator
      22. DOMObject
      23. DOMParser
      24. DOMPoint
      25. DOMPointInit
      26. DOMPointReadOnly
      27. DOMRect
      28. DOMString
      29. DOMTimeStamp
      30. DOMTokenList
      31. DOMUserData
      32. Document
      33. DocumentFragment
      34. DocumentType
      35. 元素
      36. ElementTraversal
      37. Entity
      38. EntityReference
      39. 事件
      40. EventTarget
      41. HTMLCollection
      42. MutationObserver
      43. 节点
      44. NodeFilter
      45. NodeIterator
      46. NodeList
      47. NonDocumentTypeChildNode
      48. ProcessingInstruction
      49. PromiseResolver
      50. 范围
      51. StaticRange
      52. 文本
      53. TextDecoder
      54. TextEncoder
      55. TimeRanges
      56. TreeWalker
      57. TypeInfo
      58. USVString
      59. UserDataHandler
      60. XMLDocument