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) Introducing JavaScript Link to an External Script

Alex Hird
Alex Hird
2,767 Points

When linking a HTML doc to external javascript file, can the <script src> tag be placed within the head or body tag.

When linking a HTML doc to external javascript file, can the <script src> tag be placed within the head or body tag. Thanks

Alex

2 Answers

I believe it's recommended to be placed within the end of the body tag. The file is executed in order, so if your Javascript file references any HTML tags you want these tags to load before the Javascript file

Check out this link:

http://stackoverflow.com/questions/196702/where-to-place-javascript-in-a-html-file

Alex Hird
Alex Hird
2,767 Points

Thanks for response, really helpful

script src="scripts.js" /body

Most common place. Right above last body tag.