Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
220,450 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!