0
when using <script src = "example.js"> </ script> is it also necessary to specify the path where the javascript code is located?
2 Answers
+ 2
You already gave a path to the script tag, "example.js" is a relative path that will check for the file in the same directory/folder the HTML document is located in. If you mean the absolute path (full path e.g. "C:/users/user/documents/......") then no it is not necessary and frowned apon actually.
+ 1
Yes.
Say if you had a folder called "Project" and it was setup like this:
---------
[img] -> earth.jpg, moon.jpg, sun.jpg
[scripts] -> app.js, example.js, script.js
[styles] -> bootstrap.min.css, style.css
index.html
---------
(Where "[...]" indicates a folder and "->" indicates the files in that folder)
In "index.html" to link to "example.js" you would want to use:
<script src="./scripts/example.js"></script>
(The "./" can be used to denote the current folder)