The DocumentType.replaceWith() method replaces the document type with a set of given nodes.
The DocumentType.replaceWith() method replaces the document type with a set of given nodes.
js
replaceWith(node1) replaceWith(node1, node2) replaceWith(node1, node2, /* …, */ nodeN)
node1, …, nodeN
A set of nodes to replace the DocumentType with.
None (undefined).
HierarchyRequestError DOMException
Thrown when the node cannot be inserted at the specified point in the hierarchy.
replaceWith()
js
let svg_dt = document.implementation.createDocumentType( "svg:svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", ); document.doctype.replaceWith(svg_dt);
| Specification | 
|---|
| DOM Standard  # ref-for-dom-childnode-replacewith①  | 
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
replaceWith | 
54 | 17 | 49 | No | 39 | 10 | 54 | 54 | 49 | 41 | 10 | 6.0 | 
    © 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
    https://developer.mozilla.org/en-US/docs/Web/API/DocumentType/replaceWith