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 jQuery Basics Understanding jQuery Events and DOM Traversal Using Events with Dynamically Added Elements

Button still works

The button still works for me after moving the click event to the top of the app.js. I even cleared the cache in Chrome and it still work. This is NOT a problem, obviously. Just an observation. I'm guessing it has to do with Chrome's JS engine being "smart."

2 Answers

Steven Parker
Steven Parker
229,732 Points

It doesn't matter where in the file you place the code to establish the button click handler. The entire file runs immediately on page load, but the handler itself doesn't run until the button is clicked.

I jumped the gun on this post. I was targeting '.spoiler' instead of '.spoiler button' for the .click When targeting '.spoiler button' the behavior is the same as in the video. Sorry!