how to link javascript to html ? – linking JavaScript to HTML file

how to link javascript to html : You can include JavaScript in your HTML in two ways: first of all you will include the JavaScript as an external file. JavaScript is one of the main languages used in web development nowadays.

how to link javascript to html?

To link a JavaScript file to an HTML document, use the script tag. You can also use this tag to embed JavaScript code within the HTML document.

Using the script tag to include an external JavaScript file

<script type="text/javascript" src="path-to-javascript-file.js"></script>

Linking to an External JavaScript File

Example 1

<!DOCTYPE html>
<html>
<head>
<title>free download source code - www.pakainfo.com</title>

<script src="/login/pakainfo/welcome.js"></script>

</head>
<body>

<button onClick="JavaScript:getAllProducts()">Click Me</button>

</body>
</html>

Embedded JavaScript

Example 2

<!DOCTYPE html>
<html>
<head>
<title>Welcome to pakainfo.com</title>

<script>
/* Example JavaScript function  */
function getAllProducts() {
	alert("Welcome To our best Guest Posting Website!")
	}
</script>

</head>
<body>

<button onClick="JavaScript:getAllProducts()">Click Me</button>

</body>
</html>

Link CSS and Js Files With an HTML File

Link JavaScript to HTML with the script src Attribute

Read Also:  Bootstrap Toggle switch with ajax update to mysql in Laravel

Example

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>free download javascript website</title>
  </head>
  <body>

  <script src="./main.js"></script>
  </body>
</html>

<script src="../public/js/main.js"></script>

Don’t Miss : Link JavaScript To HTML

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>

I hope you get an idea about how to link javascript to html.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.