HTML DOM
HTML DOM doctype Property
The doctype property returns the Document Type Declaration (the <!DOCTYPE> node) associated with the current document, or null if the document has no doctype.
Definition and Usage
document.doctype is a read-only property that returns the DocumentType node representing the document's <!DOCTYPE> declaration. For a modern HTML5 page (<!DOCTYPE html>), its name is "html".
Syntax
document.doctypeIt takes no arguments and returns a DocumentType object, or null when the document does not declare a doctype.
Example
const dt = document.doctype;
if (dt) {
console.log("Doctype name: " + dt.name); // "html"
} else {
console.log("No doctype declared");
}For a standards-mode HTML5 page this logs "Doctype name: html". The DocumentType object also exposes publicId and systemId, which are empty strings for HTML5 but populated for older XHTML doctypes.
The presence and form of the doctype affects whether the browser renders in standards mode or quirks mode. <!DOCTYPE html> triggers standards mode.
