Skip to main content

HTML DOM doctype Property in JAVA SCRIPT

Definition and Usage..
The doctype property returns the doctype of the HTML document, as a DocumentType object.
The DocumentType object has a name property, which returns the name of the doctype.
Note: If the document has no doctype specified, the return value is null.
Syntax: document.doctype
CODING:
<!DOCTYPE HTML>
<html>
<body>
<p>Click the button to display the doctype name of the document.</p>
<button onclick="doctypeName()">Doctype name</button>
<p><strong>Note:</strong> In Internet Explorer 8 and earlier, the doctype property returns <em>null</em> for HTML and XHTML documents, and will only work for XML documents.</p>
<p id="demo"></p>
<script>
function doctypeName() {
    var x = document.doctype.name;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

Comments