Search code examples
javascriptjquerywindowsimplemodal

How to write this from javascript to JQuery


Simple question I need these few lines of javascript in jquery. Just trying to close a modal when I select outside of it.

Thank you.

 // When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
 if (event.target == myModal) {
    myModal.style.display = "none";
}
}

Solution

  • I'm assuming the modal is being clicked "myModal" ... so ...

    $("#myModal").on("click",function() {
        $(this).hide();
    });