Where to put script.js | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Where to put script.js

i have an html document. i've put an external script inside the <script> tag within the head. i need to change some behaviour in the middle of the body tag inside a nested div which is nested inside another div, which is again nested inside another div, which is at the end nested in one more div. The question is - how to call upon a script and where to place it?

17th Jan 2017, 6:35 PM
Wolfinho
4 Answers
0
Scripts are mostly called before the </body> tag to reduce the loading time i.e to add script just do this.. <script src="yourscript.js"> </script> I hope you find what you need! :)
17th Jan 2017, 6:45 PM
DeepSPSingh
DeepSPSingh - avatar
0
ok. when i put it like that it changes nothing.. when i put it inside a script tag and call upon it just beyond the div i wanna change it works - why?
17th Jan 2017, 6:48 PM
Wolfinho
0
The script tag should be placed at the end of the body so we won't waste our time by loading the script first. To modify your div-inside other div-inside another div you could add an id to that div. So when you call it in the script, you could use document.getElementById() .
17th Jan 2017, 11:54 PM
Marcellino Chris O'vara
Marcellino Chris O'vara - avatar
0
Or maybe your external script is not in the same folder with the html file. So you will rather use : <script src="folderName/yourScript.js"></script>
17th Jan 2017, 11:56 PM
Marcellino Chris O'vara
Marcellino Chris O'vara - avatar