DocumentType.replaceWith()

The DocumentType.replaceWith() method replaces the document type with a set of given nodes.

Syntax

replaceWith(...nodes)

Parameters

nodes

A set of nodes to replace the DocumentType with.

Exceptions

HierarchyRequestError DOMException

Thrown when the node cannot be inserted at the specified point in the hierarchy.

Examples

Using replaceWith()

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);

Specifications

Specification
DOM Standard
# ref-for-dom-childnode-replacewith①

Browser compatibility

BCD tables only load in the browser

See also