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

How can .focus and .keyup be used in the same statement?

My question is regarding the following line of code:

$("#password").focus(passwordEvent).keyup(passwordEvent);

Im confused as to why the .keyup can be attached to the focus method and doesn't need to be included on the next line. Wouldn't this line of code only run the .keyup method on the results returned by the .focus method since it is attached to it? But it seems to run the 2 methods independent of each other.

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

It's something we call "method chaining". Here's some documentation on the .end() function in jQuery, but it also contains general examples of how method chaining is used. Hope this might help! :sparkles:

https://api.jquery.com/end/