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! Add JavaScript to HTML

Penelope Grayson
Penelope Grayson
6,838 Points

Why won't my content display before the second alert, even though the script is just before the closing <body> tag?

Near the end of the video, Guil moves the script for the second alert near the bottom of the page, just before the closing <body> tag. This results in the html content being displayed before the second alert.

This didn't work for me, does anyone know why? I am using Chrome.

I managed to get it to work by using a (complicated looking....to me) window.addEventListener event that I found on google, but I'd love to know why it didn't work like in the video.

Thanks!

1 Answer

Steven Parker
Steven Parker
231,269 Points

It's probably due to a difference in the behavior of browsers when the video was made. Modern ones defer rendering of the page until after all the JavaScript code has finished running.

Penelope Grayson
Penelope Grayson
6,838 Points

Ok, thank you very much Steven, that makes perfect sense!

Thanks for the clarification Steven.