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

Katarzyna Walsh
Katarzyna Walsh
24,409 Points

Why do we need to use both focus(confirmPasswordEvent) and keyup(confirmPasswordEvent) and not just focus?

Thanks for clarifying

1 Answer

rydavim
rydavim
18,814 Points

The focus event is only triggered when an element gains focus. This means that if you removed the keyup bit, your confirmPasswordEvent function would only be called when you clicked on the password field.

Adding the keyup event means that the confirmPasswordEvent function is called every time you release a key. This means that it gets called after each character you type, updating the user on whether or not they have met the requirements yet.

Hopefully that helps clarify things, but let me know if you have further questions. Happy coding!