0

I have created a modal that when I press the button will set the display attribute as block. But now I am searching a function for closing the modal if I click outside of it. Can you please fix my code or give me the better solution? ;)

<button id="myBtn">Open Modal</button>

<!-- The Modal -->
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">
    <span class="close">&times;</span>
    <p>Some text in the Modal..</p>
  </div>

</div>

This are my jQuery function the last one doesn't work.

$('#myBtn').click(function () {
            $('#myModal').css("display","block");
        });

        $('.close').click(function () {
            $('#myModal').css("display","none");
        });
        $(window).click(function(event){
            if(event.currentTarget==$('#myModal'))
                $('#myModal').remove();
        });
Riki AA
  • 21
  • 7

0 Answers0