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

CSS jQuery Basics (2014) Creating a Simple Lightbox Perform: Part 3

Method chaining instead of a function?

I'm unclear on why we can't use jQuery method chaining to hide the overlay at the end of this video like this:


instead of creating an anonymous function. Any explanation would really help solidify what we're learning for me, thanks!

2 Answers

Milo Winningham
Milo Winningham
Web Development Techdegree Student 3,317 Points

In the jQuery documentation for click, you'll see that the click method with no arguments will trigger a click event rather than attach an event handler.

When attaching an event handler, you specify what should happen after the element is clicked by providing a function that says how to hide the element. In your example, you're calling the hide method on whatever is returned by the click method, which will cause the element to be hidden immediately.

Excellent, thank you for helping clarify!