JavaScript: Script Tag

light111How to use <script> tag


There are different way available how the script tag can be used in the HTML file.

The SCRIPT tag usually added to the header section of the HTML file. 

One way is added the script elements in the script tag or else create a javascript file( .JS) that contains all the elements and add this script file into the  HTML file in the script tag.


The below screen shots are taken from Visual Studio.

The typical HTML file structure.

1

Take the path of the HTML file and put in the address bar of the Chrome/IE.  The output is shown as below:

2

The <SCRIPT> tag can be added to the HEADER section of the HTML file.

3

Here “document” is the object. When a HTML document is loaded into the window it becomes a document object that contains the content of the page. 

4

Output:

5


Another way is to create a .JS file and write JavaScript code inside it.

6

Add the PATH of the external .JS file in the Script tag of the HTML file.

7

Execute and check O/P-

8


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s