Good day and night! Please help! There is a script modal window. Clicking on the .open block opens a modal window with the .modal block. Clicking on the .close block .close modal window. Please help .open with the following: how when you click on the .open block .open also close the modal window?

 $(function () { $('.open').click(function(){ setTimeout(function(){ $(".modal").addClass("show"); }, 2500); }); $('.close').click(function(){ $('.modal').removeClass('show'); }); }); 

    2 answers 2

    $(".modal").hasClass("show") - Check if there is a show class, if there is, then we remove it, if there is no, then add it.

     $(function () { $('.open').click(function(){ if ($(".modal").hasClass("show")) { $('.modal').removeClass('show'); } else { $(".modal").addClass("show"); } }); $('.close').click(function(){ $('.modal').removeClass('show'); }); }); 

    • strange, why when you click on the button "Run code" gives an error? This is a mistake in the code you give, maybe some typo? - LADYX
    • one
      @LADYX You better add this code to yourself in the code and check its performance there. For there is no modal window for this code that needs to be opened) - Vorobey.A
    • Indeed, I apologize. Everything is working. - LADYX
    • Sauron, thank you for your help. Good luck! - LADYX 1:31 pm

    possible with so toggle jquery