Reputation: 63
The following code which am used for closing the popup using ESC Key
$(document).keyup(function(e){
if (e.keyCode === 27) {
closePopup(id);
}
});
Later, i found that was wrong, wrong in the sense, i have written the above code in .ready(), that is whenever i pressed the ESC Key it makes some process so, i changed to the following code, This seems good but whenever i hover only the action takes place
$("#"+id).hover(function() {
$(document).keyup(function(e){
if (e.keyCode === 27) {
closePopup(id);
}
});
});
Now what i need is, i need to close the popup using ESC KEY ONLY when the popup opens.
Can anyone help..?
i dont want to use document for this..!!
Upvotes: 0
Views: 6108
Reputation:
Edit: Deleted older answer misunderstand something, there is nothing bad at your first try. at first i though you are trying with an input now i read a gain its (modal, sorry about that
So
$(document).keyup(function(e) {
if (e.keyCode == 27) { <DO YOUR WORK HERE> } // esc
});
To unbind
use
$(document).unbind("keyup", keyUpFunc)......
Upvotes: 2