I am making a light box gallery widget, now i need to detect the keypress and call to a function but only when the #lightbox element is visible, and if it is not, it should ignore the key press, using jquery, i tried the following:
$("#lightbox").keyup(function(e) {
alert(e.keyCode);
if (e.keyCode == 27) { alert("a") } // esc
});
any sugestion guys?
if ($('#lightbox:visible').length && e.keyCode==27) {
or
if ($('#lightbox').is(':visible') && e.keyCode==27) {
http://api.jquery.com/visible-selector/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With