documentElement property


HTML DOM documentElement Properties

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.documentElement.nodeName;
}
</script>

</body>
</html>

Run Example»

Click the "Run Example" button to view the online example


Definition and usage

The documentElement property returns the document element of a document as an element object.

HTML document return object is HTML element.

Note: If the HTML element is missing, the return value is null.


Browser Support

QQ截图20161108165429.png

The documentElement attribute is supported by all major browsers


Syntax

document.documentElement

Technical details

##Return value: The document element of the document, as an element Object.DOM VersionCore Level 1 Document Object