Konrad Viltersten
Konrad Viltersten

Reputation: 39108

Can't capture delete key pressed in jQuery

I'm executing the following code as suggested here.

$("#textBox").on("keyup", function (event) {
  foo(event.keyCode === 8 || event.keyCode === 64);
});

function foo(special) {
  console.log(special);
}

For BackSpace it works like a charm producing true. However, Del produces false. What's up with that?!

Upvotes: 1

Views: 2921

Answers (1)

Avitus
Avitus

Reputation: 15958

It's because the keycode for delete is 46 not 64.

See: http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes

Upvotes: 6

Related Questions