Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .keypress & .keydown .which

Ok so what is the difference in .keypress and .keydown/.keyup? At present I am using .keydown which returns a .which value of 38 for my key, now if i change it to .keypress it returns a value of 109 for that same key. What is the difference and why are the values different for the same key?

like image 566
ChrisMJ Avatar asked Apr 17 '12 12:04

ChrisMJ


People also ask

What is keypress event in jQuery?

The keypress() method triggers the keypress event, or attaches a function to run when a keypress event occurs. The keypress event is similar to the keydown event. The event occurs when a button is pressed down. However, the keypress event is not fired for all keys (e.g. ALT, CTRL, SHIFT, ESC).

What is Keyup and Keydown in jQuery?

jQuery keyup() Method The order of events related to the keyup event: keydown - The key is on its way down. keypress - The key is pressed down. keyup - The key is released.

How do you find Enter key is pressed in jQuery?

The “enter” key is represent by code “13”, check this ASCII charts. To check if an “enter” key is pressed inside a textbox, just bind the keypress() to the textbox. $('#textbox').

Is keypress deprecated?

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes.


1 Answers

If you press a button it fires a keydown and releasing it fires a keyup. The keypress usually comes between those two.

keydown and keyup talk about which key has been changed. keypress tells which character that key represents.

Note that this is all browser-dependent!

See this article about the differences between the key events as implemented on various browsers.

like image 119
RvdK Avatar answered Oct 06 '22 19:10

RvdK