JavaScript and HTML

There are many ways to insert JavaScript instructions into HTML code, here you will learn one of them. Basically, the HTML document itself should have to satisfy the general conventions.

Usually JavaScript instructions are partitioned into small units which are spread up over the HTML script. The JavaScript instructions have to be put between the opening <script type="text/javascript"> and closing </script> tags. See SCRIPT - Client-side Script for more information on the SCRIPT tag.

All JavaScript instructions between the opening and closing tags should to be hidden from the browsers that do not support JavaScript. You can achieve this by putting them as HTML comments, i.e. between <!-- and -->. JavaScript comments start with //. Therefore, the general rules for JavaScript that we will follow in this course are the following:

 
<html>
<head>
<title> .... </title>

   <script type="text/javascript">
   <!-- JavaScript goes here
   .........................
   .........................
   // JavaScript comments
   .........................
   .........................
   // another JavaScript comment
   .........................
   .........................
   // JavaScript ends here -->
   </script>

</head>

<body>
   .........................

   <script type="text/javascript">
   <!-- another set of JavaScript commands
      ......................
      ......................
   // JavaScript ends here -->
   </script>

   .........................
   .........................
   .........................
   .........................
</body>
</html>