📜  检查点击是否在 div javascript 代码示例中

📅  最后修改于: 2022-03-11 15:02:54.088000             🧑  作者: Mango

代码示例1
var container = document.getElementsByClassName('container')[0];
document.addEventListener('click', function( event ) {
  if (container !== event.target && !container.contains(event.target)) {    
    console.log('clicking outside the div');
  }
});