Most likely because the button element doesn't recognize the keypress event.
Not every element have the same events.

Swap out button for input and try it again, it should work just fine. 

-----Original Message-----
From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
Behalf Of elischer.flor...@googlemail.com
Sent: Wednesday, May 27, 2009 2:29 AM
To: jQuery (English)
Subject: [jQuery] Event behaving


Hi,

I have a question why is this not working:

$("button").keypress(function(e) {
  e.preventDefault();
  alert("hello");
});

but this here:

$("button").click(function(e) {
  e.preventDefault();
  alert("hello");
});

For my understanding when I hit enter in a form keypress should work?!

thx
TC


Reply via email to