-1

I am super novice and need a quick advice. I need the close popup clicking by outside of modal.

Here is the codes. any tips about this?

    $('.login-btn').on('click', function () {
    $('.signin-parent').show();
});
$('.signin-btn').on('click', function () {
    console.log('erhan')
    $('.signin-parent').show();
    $('.signup-parent').hide();
});
$('.signup-btn').on('click', function () {
    $('.signin-parent').hide();
    $('.signup-parent').show();
});
$('.exit').on('click', function () {
    $('.signin-parent').hide();
    $('.signup-parent').hide();
})

It works finely but I click outside of popup it not close, anyone can help me? thanks

axm__
  • 2,463
  • 1
  • 18
  • 34
  • It should work if you listen for a click on `$(document)`, then in the event handler use `$.contains` to check if the event target is inside the popup. If it's not, then close it. – Robin Zigmond Sep 28 '18 at 23:05
  • when i click exit icon it closed popup its okay but i want if i click the outside of the popup it will be closed too as i say im super novice and i cant wrote a code please help – Şahin Coşkun Sep 28 '18 at 23:12

1 Answers1

0

You can assign an onclick event to the document or the body, then you can hide the pop-ups inside the event callback.

$(".login-popup").on("click",function(e){
    if($(e.target).closest(".signin").length != 0)
    return;
    $(".login-popup").hide();
})