Write JavaScript in HTML page


javascript Write JavaScript in HTML page Include JavaScript

How to insert and run the JavaScript code into an HTML page?

Instead of wandering through loads of the theory , we will prefer to discuss the way of the JavaScript writing code in HTML page. JavaScript is written between <script> </script> tag , either in the <head> tag or in <body> tag.

Syntax of Writing JavaScript

Take a look on the following below code to understand that how JavaScript applied on the HTML page. <html> <head> <title> Including JavaScript to HTML Page</title> <script type="text/javascript"> alert("Welcome to CodingPk JavaScript Tutorials"); </script> </head> </html> Output: • If we are writing the code in the HTML file or same web file etc .html , .php etc then we will write the code in <script> tag. • If we want to include the external JavaScript file then we will include by following way. <script src="javascriptfile.js"></script> In the .js file, we will not write the JavaScript code in <script> tags we need to write the above JavaScript code by just following code:

javascriptfile.js Code

alert("Welcome to CodingPk JavaScript Tutorials");We wrote the JavaScript code in external JavaScript file without the <script> tag. In the next Chapter we are going to discuss the JavaScript on-click function.
javascript Include JavaScript Chapter Next »