I have created a simple code to handle keypress
event:
var counter = 0; $('input').on('keypress', function () { $('div').text('key pressed ' + ++counter); });
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); });