JavaScript code on HTML page

Posted by tagicon_admin | July 28, 2015 | in : JavaScript

Today I will show  how to write JavaScript code on HTML page:

All the JavaScript code you have to write in  HTML page. If you do not know HTML basic then you need to learn it first.

We can write JavaScript code anywhere in html page, but below steps are preferred to write the javascript code

  • In html <head>………script ………</head> section
  • In html <body>………script ………</ body > section
  • In html <head>………script ………</head> and <body>………script ………</ body > section
  • Script in External “.js” file and include in html head section

If we want to write to the document by using a JavaScript we place the code in HTML body section

For create a JavaScript function and keep it for further use then we can use HTML head section or external .js file.

If  you want to use the same javascript in several pages or a single page then you can use external .js file to include in html page.

Example 1:

Example 2:

Example 3:

Write in a simple text file and save it “file_name.js” extension:

In html head section include the js file like below

Note: it is a good practice to ending a statement by putting semicolon “;”.

Related Posts

Leave a Reply