繁体   English   中英

如果在其中单击任何元素,如何隐藏 class?

[英]How to hide a class if any element gets clicked inside of it?

<div id="ad-container" class="overlay">
                <ins onclick="hideGFeedback()" id="overlay-ad" class="adsbygoogle"
     style="display:inline-block;width:500px;height:60px;"
     data-ad-client="ca-pub-2199974740270676"
     data-ad-slot="9684342380"></ins>
     <script>
     (adsbygoogle = window.adsbygoogle || []).push({});
     </script>
</div>
    const ad = document.getElementById("ad-container");
    ad.addEventListener('click', e => {
      console.log("test");
      ad.style.opacity = 0;
    })

如果我点击 id“ad-container”本身,此代码才有效。 但是,如何通过单击该 id 中的任何内容来使整个 div 不可见呢?

我不知道任何解决方案,因为我找不到任何答案

你可以这样做:

// this will Listen for clicks on the entire window
document.addEventListener('click', function (event) {
  event.target.style.opacity = 0
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM