HOLLA TECH - LEARN

JavaScript in <head>
 

You can place any number of scripts in an HTML document.
Typically, the script tag is placed in the head of the HTML document: 

<html>
   <head>
     <script>
     </script>
   </head>
   <body>
   </body>
</html>

 

NOTE!
There is also a <noscript> tag. It’s content will be shown if the client’s browser doesn’t support JS scripts.

JavaScript in <body>
 

Alternatively, include the JavaScript in the <body> tag. 

<html>
   <head> </head>
   <body>
    <script>
     </script>
   </body>
</html> 

 

NOTE!
It’s a good idea to place scripts at the bottom of theelement. This can improve page load, because HTML display is not blocked by scripts loading.

The <script> Tag
 

The <script> tag can take two attributes, language and type, which specify the script’s type:

<script language=“javascript” type=“text/javascript”>

</script> 

 

The language attribute is deprecated, and should not be used.

In the example below, we created an alert box inside the script tag, using the alert() function.

<html>
   <head>
     <title></title>
     <script type=“text/javascript”>
       alert(“This is an alert box!”);
     </script>
   </head>
   <body>
   </body>
</html

 

Result: 

Holla Tech - Learn JavaScript


BACK NEXT

CLICK ON THE BUTTON BELOW TO GO TO THE JAVASCRIPT MAIN COURSE PAGE. 

JAVASCRIPT MAIN COURSE PAGE

 


© License: All Rights Reserved 


CONTACT HOLLA TECH – LEARN SUPPORT