Definition and Usage..
The documentElement property returns the documentElement of the document, as an Element object.
For HTML documents the returned object is the html element.
Note: This property is read-only.
Tip: The difference between this property and the document.body property, is that the document.body element returns the body element, while the document.documentElement returns the html element
Syntax: document.documentElement
CODING:The documentElement property returns the documentElement of the document, as an Element object.
For HTML documents the returned object is the html element.
Note: This property is read-only.
Tip: The difference between this property and the document.body property, is that the document.body element returns the body element, while the document.documentElement returns the html element
Syntax: document.documentElement
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display the node name of the documentElement.</p>
<button onclick="DisplayNode()">Display Node</button>
<h2></h2>
<h3></h3>
<p id="a"></p>
<script>
function DisplayNode(){
var rootElement = document.documentElement;
document.getElementsByTagName("H2")[0].innerHTML=rootElement;
var firstTier = rootElement.childNodes;
document.getElementsByTagName("H3")[0].innerHTML=firstTier;
var p=document.getElementById("a");
for(var i=0 ; i < firstTier.length ; i++) {
p.innerHTML = p.innerHTML + firstTier[i] + "<br>";
}
}
</script>
</body>
</html>
<html>
<body>
<p>Click the button to display the node name of the documentElement.</p>
<button onclick="DisplayNode()">Display Node</button>
<h2></h2>
<h3></h3>
<p id="a"></p>
<script>
function DisplayNode(){
var rootElement = document.documentElement;
document.getElementsByTagName("H2")[0].innerHTML=rootElement;
var firstTier = rootElement.childNodes;
document.getElementsByTagName("H3")[0].innerHTML=firstTier;
var p=document.getElementById("a");
for(var i=0 ; i < firstTier.length ; i++) {
p.innerHTML = p.innerHTML + firstTier[i] + "<br>";
}
}
</script>
</body>
</html>
Comments
Post a Comment