Skip to main content

Bug Tracker

Side navigation

#3311 closed bug (fixed)

Opened September 01, 2008 06:03AM UTC

Closed November 06, 2010 07:33PM UTC

Last modified March 14, 2012 06:51PM UTC

Strange, inconsistent behavior of keypress() in FF 3 and IE 8

Reported by: jestempies Owned by:
Priority: major Milestone: 1.3
Component: event Version: 1.2.6
Keywords: keypress Cc:
Blocked by: Blocking:

Behavior of Esc key in an <input/> in Firefox 3 seems weird. To reproduce:

1) Create a page with:

<script type="text/javascript">
$(document).ready(function() {
      this.value = e.which;
      return false;

<input id="test"/>

2) While input is focused, press 'd' -- it shows '100' (correct)

3) Press Escape -- input is empty (wrong)

4) Press Backspace -- input shows '8' (correct)

5) Press Escape -- input shows '8' (wrong)

6) Press 'd' -- input shows '100' (correct)

7) Press Escape -- input shows '8' (wrong)

8) Press Delete -- input shows '0' (wrong)

9) Press Escape -- input shows '0' (wrong)

Behavior in Internet Explorer 8 is different, but also wrong. Escape is correctly captured as 27, but Backspace, Delete and cursor keys are not captured at all.

Attachments (0)
Change History (4)

Changed October 02, 2008 07:57AM UTC by -Sami- comment:1

After some debugging the ESC key behavior on FF3 it seems that this bug is because of changes made in [4330] to an if-clause in ''event.fix(event)'' function.

Things go wrong when ''charCode === 0'' and ''keyCode'' has the correct value and should be used. In this case the if-clause evaluates to ''false'' and ''event.which'' isn't assigned.

Commit message of the changeset says: "Fixes bug with charCode...", but I couldn't figure out which bug this is. So I don't know what would be the correct way to fix this issue..

Changed February 03, 2010 08:30PM UTC by mchuah comment:2

This is still a problem in the current version. It breaks many attempts to use the ''which'' property in keypress events, including testing for keys like tab and escape in FF.

In my own copy of jQuery, I've reverted the offending line changed in [4330] to what it was in the previous revision to fix this, and it seems to work without problem.

Can anyone indicate the intent of the change in [4330] and what it was supposed to fix, or can we change the code back to what it was?

Changed November 06, 2010 07:33PM UTC by dmethvin comment:3

resolution: → fixed
status: newclosed

This problem was fixed in jQuery 1.4.3.

Changed July 06, 2011 08:09PM UTC by anonymous comment:4

I am still having this problem. I am using jQuery 1.6.2 and Firefox 3.6.17. e.which returns 0.

Here is an example of code that demonstrates the problem:

<script src=""></script>

<script type="text/javascript">
$(document).ready(function() {
	$('#test').keypress(function(e) {

<form action="myaction">
<input type="text" name="test" id="test">


The result of pressing escape when the cursor is in the text field is an alert box with "0".