Javascript and DOM - <script></script>


#1

I am on Javascript and the DOM. I am on step 2/16, and I'm on the part that uses the function to link the index.HTML page to the main.js page in the example. I understand the purpose of the function pretty well, but I am confused on the coding. The coding they want it . The part that is really throwing me off is why there is js/ added infront of the main.js page. Does anybody know why? Thanks.


#2

I think I understand now. But when the pop up that comes up say [object HTMLCollection] where is it getting that from?


#3

Hi there... I was searching the forum for a question of my own and saw this post. I'm not taking that course/lesson, but I might be able to answer your question about js/ being in front of a main.js file. I'm assuming it says something to the extent of <script src='js/main.js'></script>

Basically this is telling the browser that the main.js file is within a folder titled js The path for your files always starts at the level where your index.html file is located.

So imagine you have a folder on your desktop titled "My Website" and in that folder you have an index.html file and a sub-folder titled js. If you saved your main.js file in the js folder -- for no reason other than to organize it better -- like so:

Desktop / My Website / index.html
Desktop / My Website / js / main.js

than you would need to point your index.html file to the path js/main.js.

Conversely, if you're "My Website" folder only had an index.html file and a main.js file:

Desktop / My Website / index.html
Desktop / My Website / main.js

than you would only need to say<script src='main.js'></script>, since main.js is at the same level as index.html


#4

Gotcha, thanks man! Still confused on why what comes up in the pop up comes in but I get the link now!


#5

If you post a screenshot, I'll try and help you understand :slight_smile:


#6

This topic was automatically closed after 7 days. New replies are no longer allowed.