Javascript DOM HTML Document head Property get

Introduction

Get the id of the <head> element of the current document:

var x = document.head.id;

Click the button to display the id of the head element in the document.

View in separate window

<!DOCTYPE html>
<html>
<head id="myHead">
  <title>My title</title>
</head>/*from   w  w  w . j av a  2 s .  c  o m*/
<body>
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
  var x = document.head.id;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The head property returns the <head> element of the current document.

If there are more than one <head> element in the document, this property returns the first one.




PreviousNext

Related