JavaScript keypress event not raised on Android browser

alex.mironov picture alex.mironov · Jan 10, 2014 · Viewed 57.5k times · Source

I have created a simple code to handle keypress event:

var counter = 0;        
$('input').on('keypress', function () {
    $('div').text('key pressed ' + ++counter);
});

JSFiddle.

But keypress event handler is not raised on mobile browser (Android 4+, WindowsPhone 7.5+). What could be the issue?

Answer

Adam Hughes picture Adam Hughes · Jun 26, 2014

I believe keypress is deprecated now. You can check in the Dom Level 3 Spec. Using keydown or keyup should work. The spec also recommends that you should use beforeinput instead of keypress but I'm not sure what the support of this is.