Incorporating JavaScript in HEAD element

You can place <script> tag in HEAD element of the HTML document. The <script> in the head element executes when you perform some action.

Example: when you click a button.

Demo

Let's create a document called ScriptInHead.html



Syntax: The syntax for placing snippet in HEAD section is.

  1. <HEAD>  
  2. <SCRIPT type=”text/javascript”>  
  3. Script goes here  
  4. </SCRIPT>  
  5. </HEAD>  
Write the script in HEAD element

 



Execute the script by Opening the file in the Web Browser. If you are using Internet Explore click on “Allow Blocked Content” to allow the script to execute and you are using Mozilla Firefox then click on allow “ActiveX Controls”.



This example creates a webpage by adding the script in the HEAD element. The script displays a message when the page loads.

Ebook Download
View all
Learn
View all