Closing Modal Popup by Clicking Away from It

泄露秘密 提交于 2019-11-29 16:39:32

Try this:

$(document).ready(function(){
$('#overlay').bind('click', function(event){
    if (event.target == $('#overlay').get(0))
        overlay(); 
});

You will have to move the code of the the overlay from the modal window. Separating this, you will not have the overlay as a parent of the window and the click event will trigger only on the overlay.

<div id="overlay"> </div>
<div id="modalWindow">
    <p>Content you want the user to see goes here.</p>
</div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!