Insert, replace or remove a
DocumentType
node within aDocument
.
Node.js >= 10
is required. To install, type this at the command line:
npm install assign-dom-doctype
ES Module:
import assignDoctype from 'assign-dom-doctype';
CommonJS Module:
const assignDoctype = require('assign-dom-doctype');
Insert or replace:
const newDoctype = document.implementation.createDocumentType('qualifiedNameStr', 'publicId', 'systemId');
assignDoctype(newDoctype, document);
Remove:
assignDoctype(null, document);
The Document
's previous doctype
value will be returned.
Depending on your target browsers, you may need polyfills/shims for the following: