Script Src Attribute
The ‘src’ attribute in a tag is the path to an external file or resource that you want to link to your HTML document.
<html lang="en"> <head> <title>Script Src Attribute Example</title> </head> <body> <script src="./script.js"></script> </body> </html>
This would point to a file named ‘script.js’ that is in the same directory as the .html file. You can also link to other directories by using ‘..’ in the file path.
This jumps up one directory level then into a ‘public’ directory then to a ‘js’ directory and then to the ‘script.js’ file.
You can also use the ‘src’ attribute to link to external .js files hosted by a third party. This is used if you don’t want to download a local copy of the file. Just note that if the link changes or network access is down, then the external file you are linking to won’t work.
This example links to a jQuery file.