Click outside div to hide div in pure JavaScript

前端 未结 6 1574
栀梦
栀梦 2020-12-11 02:50

I want to make a popup that should appear once a button is clicked and disappear once the user clicks outside of the box.

I\'m not sure how to make the div disappear

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-11 03:27

    el.onmouseleave = function(){
      document.body.onclick = function(){
        el.style.display = 'none';
        document.body.onclick = null;
      }
    }
    

提交回复
热议问题