How to link a JavaScript file to an HTML file?

Spread the love

Sometimes, we want to link a JavaScript file to an HTML file.

In this article, we’ll look at how to link a JavaScript file to an HTML file.

How to link a JavaScript file to an HTML file?

To link a JavaScript file to an HTML file, we use a script tag.

For instance, we write

<!DOCTYPE html>
<html>
  <head>
    <script type="text/javascript" src="jquery-3.3.1.js"></script>
    <script type="text/javascript">
      alert("hello");
    </script>
  </head>
  <body>
    <!-- -->
  </body>
</html>

to add script tags to reference jQuery with

<script type="text/javascript" src="jquery-3.3.1.js"></script>

And we add a script tag with our own code with

<script type="text/javascript">
  alert("hello");
</script>

Conclusion

To link a JavaScript file to an HTML file, we use a script tag.

Leave a Reply

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