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.

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.