I am working a project which uses a function to show a modal dialog. The dialog can be hidden by calling the hideModal() function. This function is triggered by:
- Pressing the ESC key
- Clicking on the modal background
- Clicking on the close button
My current code is:
$("#modal").click(function() {
hideModal();
});
$("#modal-object-container > a").click(function(e) {
hideModal();
e.preventDefault();
});
$(document).keydown(function (e) {
if (e.keyCode == '27') {
hideModal();
}
});
I have the feeling there should be a faster way to bind all these events at once.
click
events you can use event delegation , but that's about it – tereško Nov 24 '11 at 1:21