Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Storing and Tracking Information with Variables Capturing Visitor Input

Daniel Valles
Daniel Valles
8,157 Points

Placement of <script src="scripts.js"></script>

In the video the above referenced statement is placed within a <div>. How come? Why not under it just before the body closing tag? That was where I thought it was suppose to be placed from the instructions. Some insight please.

2 Answers

Erik Nuber
Erik Nuber
20,629 Points

I think as long as it's the last thing in your file before the body tag, it should run with the same functionality. I would have removed it from the div tag and placed it just above the closing body tag myself. I don't think you will see this like it is in this video as you move further through the javascript courses. It does effect how you write your code based on where the script tag is located.

for example if you have it in the header tag, you would need to do a document.ready and then possibly an event listener call for certain actions because you need the page to finish loading. When the script is just above the body tag, you could do just an event listener because the document has already loaded. So placement does matter.

Daniel Valles
Daniel Valles
8,157 Points

Thank you Erik for your insight and speedy response. Very much appreciated. With kind regards, Daniel