HTML DOM doctype attribute
HTML DOM doctype Attributes
Instance
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <p id="demo">单击按钮来显示文档类型名称。</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ var x=document.getElementById("demo"); x.innerHTML=document.doctype.name; } </script> <p><strong>注意:</strong>在IE 8和更早的版本,对于HTML和XHTML文档doctype属性返回<em>null</em> ,只在XML文档下工作。</p> </body> </html>
Run Example»
Click the "Run Example" button to view the online example
Definition and usage
The doctype attribute can return the Document Type Declaration related to the document.
To read more about document type objects, please view the Document Type Object Reference Manual.
Note: If the document does not specify a document type, the return value is null.
Browser support
All major browsers support the doctype attribute
Note : This property returns null when Internet Explorer 8 and IE earlier versions display HTML and XHTML documents, but XML documents are supported.
Syntax
document.doctype
Technical details
Return value: | The document type of the document, as a DocumentType object . |
---|---|
DOM Version | Core Level 1 Document Object |