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 Password Confirmation Form Perform: Part 1

Naivedya Bansal
Naivedya Bansal
5,483 Points

keyup() and keypress()

What is the difference between keyup() and keypress()? and how did we decide which to use in this case?

2 Answers

lihaoquan
lihaoquan
12,045 Points

When the key on the keyboard is pressed DOWN, it triggers keydown(), when the key on the keyboard is released ( When your finger lets go ), the keys pop back UP and thus triggers keyup(). When the key is PRESSED ( no matter if the key is pressed down or up, it'll be triggered once the key is pressed ) , it triggers keypress().

Nicholas Woods
Nicholas Woods
6,260 Points

I think video games explain this well. Say you are swinging a sword and you need to hold down a button to charge up it's power keydown(), and then let go of the button to attack keyup(). This may be a really bad analogy as I am still very much a beginner myself. But this how I understand it.