I created a lightbox using the following script:
<script type="text/javascript">
$(document).ready(function(){
$(".BtnAction").click(function(){
var objPopup = $($(this).attr("rel"));
var mask = $("<div/>", {
id : "mask",
style: "background:#000; display:block;top:0;left:0;position:absolute;opacity:0.8;filter: alpha(opacity=80);width:100%;height:100%;z-index:9998;",
click: function(){
$(objPopup).hide();
$(this).remove();
}
});
$(".PopupWrap").before(mask);
objPopup.show();
});
$(".CloseIcon").click(function(){
$(this).parent().hide();
$("#mask").remove();
});
});
</script>
How can I implement the ESC key so that when it is clicked, the lightbox will close as well?
Thanks so much.
You can add an esc key listener to the document within your $(document).ready() block, and repeat the code you currently have for the $(‘.CloseIcon’).click() function, but target the lightbox by it’s Id:
https://stackoverflow.com/a/3369624/1010337