Reputation: 117
So, I've been trying to play with the js on this codepen so that when you click the background, it closes the modal... But, I have two problems:
Could you guys help? Anything so I can learn and fix :)
Here below is the js code:
$('.button').click(function(){
var buttonId = $(this).attr('id');
$('#modal-container').removeAttr('class').addClass(buttonId);
$('body').addClass('modal-active');
})
$('#modal-container').click(function(){
$(this).addClass('out');
$('body').removeClass('modal-active');
});
Thanks! :D
Upvotes: 1
Views: 52
Reputation: 33933
If your question is about how to prevent the modal to close on a direct click on it, but keeping a click on the background to close it (Like if you want to insert a button or anything into it)...
This will do:
$(".modal").click(function(){
return false;
});
Upvotes: 1