I would like to detect whether the user has pressed any key when a modal is shown. I tried the following code but the events are not fired.
Code snippet:
I found the solution to my problem. It seems like I should not point to the id of the modal so that the keypress event will be detected.
$(document).on('keydown keyup input click', function (e) {
if($('#modal_confirmation_dp_change').is(':visible')) {
var key = e.which;
if (key == 13) { //This is an ENTER
$('#changed_dp_ok').click();
}
}
});