First you need to download the jQuery library from https://jquery.com/ then load the jQuery library the following way within your HTML head tags.

Then you can test whether jQuery is working by adding your jQuery code after the jQuery loading script.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<!--LINK JQUERY-->
<script type="text/javascript" src="jquery-3.3.1.js"></script>
<!--PERSONAL SCRIPT JavaScript-->
<script type="text/javascript">
   $(function(){
      alert("My First jQuery Test");
   });
</script>

</head>
<body><!-- Your web page --></body>
</html>

If you want to use your jQuery scripts file separately, you must define the external .js file this way after the jQuery library loading.

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

Test in real time

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<!--LINK JQUERY-->
<script type="text/javascript" src="jquery-3.3.1.js"></script>
<!--PERSONAL SCRIPT JavaScript-->
<script type="text/javascript">
   $(function(){
      alert("My First jQuery Test");
   });
</script>

</head>
<body><!-- Your web page --></body>
</html>

Answer from Swarne27 on Stack Overflow
Top answer
1 of 6
260

First you need to download the jQuery library from https://jquery.com/ then load the jQuery library the following way within your HTML head tags.

Then you can test whether jQuery is working by adding your jQuery code after the jQuery loading script.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<!--LINK JQUERY-->
<script type="text/javascript" src="jquery-3.3.1.js"></script>
<!--PERSONAL SCRIPT JavaScript-->
<script type="text/javascript">
   $(function(){
      alert("My First jQuery Test");
   });
</script>

</head>
<body><!-- Your web page --></body>
</html>

If you want to use your jQuery scripts file separately, you must define the external .js file this way after the jQuery library loading.

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

Test in real time

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<!--LINK JQUERY-->
<script type="text/javascript" src="jquery-3.3.1.js"></script>
<!--PERSONAL SCRIPT JavaScript-->
<script type="text/javascript">
   $(function(){
      alert("My First jQuery Test");
   });
</script>

</head>
<body><!-- Your web page --></body>
</html>

2 of 6
73

This is how you link a JS file in HTML

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script> - tag is used to define a client-side script, such as a JavaScript.

type - specify the type of the script

src - script file name and path

🌐
W3Schools
w3schools.com › tags › att_script_src.asp
HTML script src Attribute
If you want to run the same JavaScript ... the same script over and over again. Save the script file with a .js extension, and then refer to it using the src attribute in the <script> tag....
Discussions

How to link JS from an extern file in HTML
When I link my JS file from HTML and call the function stored in the external file, nothing happens. I tried including it in the , but still nothing shows up. Here is the HTML file: &... More on stackoverflow.com
🌐 stackoverflow.com
Linking external javascript file into html
Hello, i have written a html file which works perfectly including some javascript functions. Now i wrote an external javascript and moved those function in to it. AS next i have tried to link this javascript file in my html file. Both files are stored in the flash of my ESP32S3. More on forum.arduino.cc
🌐 forum.arduino.cc
1
0
May 16, 2024
How to link js file to html file without the need to use full paths ?
- Use this to link your JS file. Make sure that the file path in the src attribute matches the actual file path and name of your JavaScript file. If you're still having trouble, double-check that both your HTML and JavaScript files are in the same directory and that the file names and extensions are correct. More on reddit.com
🌐 r/learnjavascript
5
7
April 8, 2023
Linking javascript to html
Can you post your code? Specifically, can you post your script tags · It could be that the link to the app.js file isn’t correct. Maybe it’s in a different folder. But this is just an assumption, as I don’t have too much to go off of. If you can, give us the specific errors you’re ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
0
May 14, 2021
🌐
Quora
quora.com › How-do-I-link-an-external-JS-file-in-HTML
How to link an external JS file in HTML - Quora
Answer (1 of 2): [code]Below is the example with jquery link external [/code]
🌐
Quackit
quackit.com › html › howto › how_to_link_javascript_to_html.cfm
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. To link to an external JavaScript file, use <script src="myExternalFile.js"></script> where myExternalFile.js is the location of the external file.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-add-javascript-to-html
How to Add JavaScript to HTML for Beginners | DigitalOcean
July 14, 2025 - For larger scripts or code that needs to be used across multiple pages, the most effective and professional solution is to place the JavaScript in a separate file with a .js extension. You can then link to this external file from your HTML using the <script> tag with the src (source) attribute.
🌐
Medium
medium.com › @ryan_forrester_ › how-to-link-a-javascript-file-to-html-complete-guide-1b68fafe774b
How to Link a JavaScript File to HTML: Complete Guide
November 7, 2024 - The `src` attribute specifies where to find the JavaScript file, in this case, `script.js`, which is located in the same folder as the HTML file. - Placing `<script>` just before the closing `</body>` tag ensures the HTML content loads first.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › html › how-to-link-javascript-file-to-a-separate-html-file
How to Link JavaScript File to a Separate HTML File? - GeeksforGeeks
July 23, 2025 - <!DOCTYPE html> <html> <head> <title>Link JavaScript file to a separate HTML file </title> </head> <body> <h1 style="color: green;">GeeksforGeeks</h1> <h3>Using src attribute in &lt;script&gt; Tag </h3> <button onclick="h1ChgFn()"> Change Heading </button> <script src="script.js"></script> </body> </html>
🌐
Linode
linode.com › docs › guides › how-to-add-javascript-to-html
An Essential Guide on How to Add JavaScript to HTML | Linode Docs
May 5, 2022 - To include an external JavaScript file in HTML, you still use the <script> tag. However, instead of adding JavaScript directly between the <script> tags, you use the tag’s src attribute to point to an external JS file.
🌐
Arduino Forum
forum.arduino.cc › projects › programming
Linking external javascript file into html - Programming - Arduino Forum
May 16, 2024 - Hello, i have written a html file which works perfectly including some javascript functions. Now i wrote an external javascript and moved those function in to it. AS next i have tried to link this javascript file in my html file. Both files are stored in the flash of my ESP32S3.
🌐
Scaler
scaler.com › home › topics › how to link javascript to html?
How to Link JavaScript to HTML? - Scaler Topics
March 22, 2024 - To link external javascript, we have to write the scripting logic inside a separate file(.js file extension) and then reference the file name by writing its name inside src attribute of the <script> tag.
🌐
DEV Community
dev.to › dcodeyt › the-best-way-to-load-external-javascript-files-into-your-html-file-3o5d
The Best Way to Load External JavaScript Files Into Your HTML File ✅ - DEV Community
August 29, 2022 - <!DOCTYPE html> <html> <head> <title>Website Title</title> <script src="js/main.js" defer></script> </head> </html> // src/main.js // Only executes once the DOM has been parsed - no errors! 😏 const myInput = document.getElementById("myInput"); ... You can find a complete course on the JavaScript DOM which goes over some of the topics covered in this post at the link below 👇 https://www.udemy.com/course/the-ultimate-javascript-dom-crash-course/?referralCode=DC343E5C8ED163F337E1
🌐
Simmons University
web.simmons.edu › ~grabiner › comm244 › weeknine › including-javascript.html
Including JavaScript In Your Page
To include an external JavaScript file, we can use the script tag with the attribute src. You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. <script type="text/javascript" src="path-to-javascript-file.js"></script> ...
🌐
Reddit
reddit.com › r/learnjavascript › how to link js file to html file without the need to use full paths ?
r/learnjavascript on Reddit: How to link js file to html file without the need to use full paths ?
April 8, 2023 -

I set up a simple project in Vscode , I made a simple html and js file . First one , I test by put all js file content into script tag in html file , worked fine . The thing is when I create new js file , it stop linked together.

The structure of my project is Projects/project1/project.html and project.js inside the same folder as project.html

I have tried src=“project.js” ,”/project.js”…. Any combination possible but it didnt worked, the only thing that worked is the full path : “file:///Users/admin/Desktop/Projects/project1/project.js “ which I think really long

So what is the right path to link those two file without the need to use full path in this projects ?

🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Linking javascript to html - JavaScript - The freeCodeCamp Forum
May 14, 2021 - i have 3 files. app.js index.html gallery.html i have a script tag on the index.html page so it links the app.js to the index.html i also have the same script tag on the gallery.html the app.js file has code that c…
🌐
Scientech Easy
scientecheasy.com › home › blog › how to link external javascript in html
How to Link External JavaScript in HTML - Scientech Easy
February 24, 2025 - An external JavaScript source file is a simple text file that ends with the file extension .js. The source file only contains JavaScript code and can be linked to a web page via src attribute of <script> tag. The third and the most popular method to link JavaScript in HTML page is by using ...
🌐
W3Schools
w3schools.com › js › js_whereto.asp
JavaScript Where To
<!DOCTYPE html> <html> <body> <h2>Demo JavaScript in Body</h2> <p id="demo">A Paragraph</p> <button type="button" onclick="myFunction()">Try it</button> <script> function myFunction() { document.getElementById("demo").innerHTML = "Paragraph changed."; } </script> </body> </html> Try it Yourself » · Placing scripts at the bottom of the <body> element improves the display speed, because script interpretation slows down the display. ... External scripts are practical when the same code is used in many different web pages. JavaScript files have the file extension .js.
🌐
YouTube
youtube.com › watch
How To Link An External JavaScript File In HTML *2023 - YouTube
How To Link An External JavaScript File In HTML5 *2023This is a video tutorial on how to link an external JavaScript file that is in folder to an html docume...
Published   February 2, 2022
🌐
Sololearn
sololearn.com › en › Discuss › 2402439 › how-to-use-external-javascript-what-should-i-type-in-js-file-so-it-will-load-in-html-file
How to use external JavaScript? What should I type in .js file so it will load in html file? | Sololearn: Learn to code for FREE!
I saved both files in same folder but JavaScript in not loading in my html file. ... I did, it worked... Html: <!doctype html> <html> <head> <title></title> </head> <body> <script type="text/javascript" src="code.js"></script> </body> </html> Js: (code.js) document.write("hello world"); It was ok... ... But it worked for me with or without it, so it might be something else... did you add a link tag within your head tags ?
🌐
TutorialsPoint
tutorialspoint.com › How-to-use-external-js-files-in-an-HTML-file
How to use external “.js” files in an HTML file?
<!DOCTYPE html> <html> <body> ... </script> </body> </html> External JavaScript means, write the code in another file having a .js extension and then try to link the file inside the <head> or <body> section....