I’v read around that you could bind different events using bind() function obviously. But i’m having troubles understanding the syntax, especially when there are specific functions like keydown, that take arguments. Here’s my code example:
$('#closePopup').click(function(){
popupbg.add(popup).fadeOut();
});
$(document).keydown(function(e){
if(e.keyCode==27){
popupbg.add(popup).fadeOut();
}
});
Is there a way to bind/on those 2 triggers, so i can avoid duplicating popupbg.add(popup).fadeOut(); statement? Like (on click and keypress(e)) do this
You can’t bind different events to different objects in one statement unfortunately.
You could put that code in a function and call that function in both the events to avoid duplicating the code: