Computer >> Computer tutorials >  >> Programming >> Javascript

How to work with document.head in JavaScript?


Use the document.head property in JavaScript to get the id of the <head> tag of the document. You can try to run the following code to implement document.head property in JavaScript −

<!DOCTYPE html>
<html>
   <head id = "myid">
      <title>JavaScript Example</title>
   </head>
   <body>
      <h1>Employee Information</h1>
      <form>
         Name: <input type = "text" name = "name" value = "Amit"><br>
         Subject: <input type = "text" name = "sub" value = "Java">
      </form>
      <script>
         var a = document.head.id;
         document.write("<br>Head element id? "+a);
      </script>
   </body>
</html>