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 trialammarkhan
Front End Web Development Techdegree Student 21,661 PointsWhat triggers the js?
I couldn't figure out, how to run that code in my HTML page. there isn't any trigger to do so, so how come when page run the code on load?
3 Answers
Steven Parker
231,269 PointsNormally, the JavaScript code is loaded by a <script>
tag in the HTML, and it runs immediately after it is loaded.
ammarkhan
Front End Web Development Techdegree Student 21,661 PointsNo I mean, in the video how does Dave make the script load when the page loads. Either a event happens or something get called?
Steven Parker
231,269 PointsI think we are talking about the same thing. When the page loads, the HTML contains one or more <script>
tags that identify the JavaScript modules. As each tag is encountered during loading, the script code is loaded and immediately executed. This is an automatic browser function and does not require anything special in the code.