doniyor
doniyor

Reputation: 37856

Bootstrap modal close on enter key press

I am trying to write a code which enables one to close the open bootstrap modals once you hit the enter key.

this is my code:

$(document).keyup(function(e) {
     if(e.keyCode==13){
         if(!$(e.target).closest('.modal fade in').length) {
             $('.modal').each(function(){
                $(this.previousSibling).modal('hide');
            });
         }
     }
});

please help, what am i doing wrong?

Upvotes: 0

Views: 4493

Answers (1)

doniyor
doniyor

Reputation: 37856

I did simply:

$('.modal').modal('hide');

and all open modals closed.

what the heck! :D

Upvotes: 2

Related Questions