Add JavaScript to HTML

There are following three ways through which we can add the JavaScript code into the HTML document:

  1. Include the JavaScript code in … tag.
  2. Include the JavaScript code between the … tag and after the closing of the body tag.
  3. Link the separate file of JavaScript in HTML

Include the JavaScript Code in tag.

In this section, you will learn to include the JavaScript code between the and tag.

Syntax

In the above syntax, the JavaScript code written between the tag is put between the and tag in HTML file.

Example

Test it Now

Output:

Add JavaScript to HTML

2. i) Include the JavaScript code in the tag.

In this section, you will learn about how to include the JavaScript code in-between the and tag.

Syntax

In the above syntax, the JavaScript code written between the tag is put in-between of the and tag in HTML file.

Example

Test it Now

Output:

Add JavaScript to HTML

ii) Include the JavaScript code after the tag.

In this section, you will learn to include the JavaScript code after the tag.

Syntax

In the above syntax, the JavaScript code written between the tag is put after the … tag in HTML file.

Example

Test it Now

Output:

Add JavaScript to HTML

Link the Separate file of JavaScript in HTML

In this section, you will learn to include the file of JavaScript code in the HTML file.

Syntax

In the above syntax, the src is an attribute of

Test it Now

Output:

Add JavaScript to HTML
Next TopicHTML Background Image




Hot Tutorials

Contact US

Email:[email protected]

Add JavaScript to HTML
10/30