HTML - DOM Document doctype Property



The doctype property returns the DTD (Document Type Declaration) that are associated with the current HTML document. It is a read-only property. It returns the doctype name as the DocumentType object and returns null if no DTD is specified for the given document.

Syntax

document.doctype;

Return value

It returns the doctype as the DocumentType object.

Example of HTML DOM Document 'doctype' Property

The following example gives doctype of HTML document.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM document doctype Property
    </title>
</head>
<body>
    <h3>
        HTML DOM document doctype Property
    </h3>
    <button onclick="fun()">Get doctype</button>
    <p>The doctype for this HTML document is:</p>
    <p id="type"></p>
    <script>
        function fun() {
            let x = document.doctype.name;
            document.getElementById("type").innerHTML = x;
        }
    </script>
</body>
</html>

Supported Browsers

Property Chrome Edge Firefox Safari Opera
doctype Yes 1 Yes 12 Yes 1 Yes 1 Yes 12.1
html_dom.htm
Advertisements