Javascript DOM HTML Document doctype Property

Introduction

Get the doctype name of an HTML document:

var x = document.doctype.name;

Click the button to display the doctype name of the document.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {/*from  w w w .ja  v  a2 s .  co m*/
  var x = document.doctype.name;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

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.

If the document has no doctype specified, the return value is null.




PreviousNext

Related