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 (2014) Creating a Password Confirmation Form Perform: Part 2

Patrick Vanegas
Patrick Vanegas
6,971 Points

I understand most of it, but still confused as to why andrew chains all of these methods together in one line.

$password.focus(passwordEvent).keyup(passwordEvent).focus(confirmPasswordEvent).keyup(confirmPasswordEvent);

From my understanding, he's checking the confirm box while the user is inputting the password. Am I on the right track?

1 Answer

Steven Parker
Steven Parker
218,813 Points

Method chaining is a convenience and also makes code more compact.

You could always perform each operation separately, but since chaining is supported, it's convenient to just select the element one time and then chain all the operations you want to perform on it.