Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
59
rated 0 times [  65] [ 6]  / answers: 1 / hits: 18868  / 15 Years ago, fri, june 26, 2009, 12:00:00

I'm porting some old Javascript to jQuery:



document.onkeyup = function (event) {
if (!event) window.event;
...
}


this code works on all major browsers. My jQuery code looks like:



$(document).keyup = function (event) {
...
}


however this code is not working (the function is never triggered at least in IE7/8). Why? How to fix?


More From » jquery

 Answers
77

The jQuery API is different:



$(document).keyup(function (event) {
...
});


jQuery.keyup is a function which takes as an argument the callback. The reason behind it is to let us assign multiple keyup (or whatever) events.



$(document).keyup(function (event) {
alert('foo');
});

$(document).keyup(function (event) {
alert('bar');
});


There's also keyup() without an argument, which will trigger the keyup event associated with the respective element.


[#99234] Tuesday, June 23, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sabinal

Total Points: 144
Total Questions: 112
Total Answers: 107

Location: Ghana
Member since Mon, Aug 22, 2022
2 Years ago
;