Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery bind keyup to body in firefox

i m binding keyup function in jquery to body which works in every browser except firefox

the code: -

 $('body').bind('keyup', function(e) {
    //alert ( e.which );
    alert('testing');

});

how do i do it for firefox. it does not responds at all

thanks

like image 730
Pradyut Bhattacharya Avatar asked Jan 11 '11 07:01

Pradyut Bhattacharya


People also ask

What is event listener Keyup?

The keyup event is fired when a key is released. The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered. For example, a lowercase "a" will be reported as 65 by keydown and keyup , but as 97 by keypress .

What is the use of Keyup function?

The keyup() is an inbuilt method in jQuery which is used to trigger the keyup event whenever User releases a key from the keyboard. So, Using keyup() method we can detect if any key is released from the keyboard.

Does Keyup work on mobile?

You should add a input event. It works on both mobile and computer devices.


1 Answers

bind the event to the document instead:

$(document).bind('keyup', function(e) {
    alert('testing');
});

You can make almost any node receive keyboard events. In "modern" browsers, you can setup a tabIndex. After that the event is focusable.

$(document.body).attr('tabIndex', 1).bind('keyup', function(e) {
    alert('testing');
});
like image 101
jAndy Avatar answered Sep 28 '22 21:09

jAndy