Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
105
rated 0 times [  106] [ 1]  / answers: 1 / hits: 48417  / 14 Years ago, tue, october 19, 2010, 12:00:00

Code:



$('#Inputfield').keyup(function(e)
{
if(e.which == 13)
{
functionXyz();
}
else
{
functionZyx();
}
});


$(document).keyup(function(exit) {
if (exit.keyCode == 27) { functionZzy(); }
});


Question: How to remove the keyup event handler of keyCode == 27 and keep the other $(document).keyup event handlers intact?


More From » jquery

 Answers
17

You have to use a named function so you can reference that specific handler when calling .unbind(), like this:



function keyUpFunc(e) {
if (e.keyCode == 27) { functionZzy(); }
}
$(document).keyup(keyUpFunc);


Then later when unbinding:



$(document).unbind(keyup, keyUpFunc);

[#95256] Sunday, October 17, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rayvenc

Total Points: 666
Total Questions: 125
Total Answers: 99

Location: Northern Ireland
Member since Mon, Nov 14, 2022
2 Years ago
;