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 Hello, JavaScript! JavaScript Practice Challenge

JS Loads Before HTML

Hi, everobody! An issue with the loading of JS code I didn't change anything in HTML file. JS code stays before </body> Despite it alert(""); loads before <h1> and sometimes before the page at all

1 Answer

Steven Parker
Steven Parker
231,261 Points

The HTML code actually loads first, but the browser doesn't render it to the screen until the JavaScript program runs and finishes. So it's normal for any "alert" messages in the js code to show before the page does.

Hi, Steven, Thanks. Maybe There is any solution for such issue?

Steven Parker
Steven Parker
231,261 Points

This is normal operation, it doesn't require a "solution". When communicating from the program, you use "prompt" and "alert". When communicating through the web page, you use event handlers and DOM updates.

Techniques for using event handlers will be covered in later courses.