how to add javascript to html-min

How to add JavaScript to HTML

How to add JavaScript to HTML If you use same JavaScript in different pages, This is not best things to do. You should create an external JavaScript file instead of writing the same script over and over again.

Make a script file and save with .js extension then you can link the external JavaScript file using src attribute in <script> tag.

<script type="text/javascript" src="custom.js"></script>

<script> – This tag is used to define a script, such as a JavaScript.
type – specify the type of the script i.e. “text/javascript”
src – script file name and path i.e. “custom.js” with the correct path.

Path May be:

Absolute URL – Refer to another website (src=”https://developerhelps/custom.js”)
Relative URL – Refer to a file within a website (src=”/scripts/custom.js”)

Note: To link a JavaScript file with your HTML, you only have to add the source of the script inside the <body> tag or <head> tag.

Javascript in HTML Examples

Example 1 :

<html>
<head>
</head>
<body>

<script type="text/javascript" src="custom.js"></script>
</body>
</html>

Example 2 :

<html>
<head>
<script type="text/javascript" src="custom.js"></script>
</head>
<body>

</body>
</html>

Thanks for the reading post. I hope you like and understand the post. If you have any doubt regarding this post please comment below.

More Related Post

Leave a comment

Your email address will not be published. Required fields are marked *

0 0 0
FOLLOW ON