< Javascript Tutorial

Javascript where to place it

← Previous Next →

Since javascript isn't HTML, you will need to let the browser know in advance when you enter javascript to an HTML page. This is done using the <script> tag.  

The browser will use the <script  type="text/javascript"> and </script> to tell where javascript starts and ends.  
Consider this example:  

        <title>My First Javascript Page</title> 
<script type="text/javascript"> 
         alert("Hello world!!!"); 

The word alert is a standard javascript function that will cause an alert box to pop up on the screen.
The user will need to click the "OK" button in the alert box to proceed.
By entering the alert command between the  <script type="text/javascript"> and </script> tags, the browser will recognize it as a javascript command.  

If we had not entered the <script> tags, the browser would simply recognize it as pure text, and just write it on the screen.

Note: You can enter javascript in both the <head> and <body> sections of the document.
              In general however, it is advisable to keep as much as possible in the <head> section.  

← Previous Next →