Skip to content
Advertisement

JavaScript keypress event not raised on Android browser

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?

Advertisement

Answer

Use the keyup event:

// JavaScript:
var counter = 0;        
document.querySelector('input').addEventListener('keyup', function () {
    document.querySelector('div').textContent = `key up ${++counter}`;
});

// jQuery:
var counter = 0;        
$('input').on('keyup', function () {
    $('div').text('key up ' + ++counter);
});
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement