当单击DIV中的IFRAME时删除DIV元素

Remove DIV element when IFRAME inside that DIV is clicked

本文关键字:DIV 删除 元素 中的 单击 IFRAME      更新时间:2023-09-26

我想在单击iframe子元素时删除iframediv元素。我想关闭div内的谷歌广告,当广告被点击。我该怎么做呢?

这是我的HTML文档:

<div class="iframediv">
    <iframe src="otherdomin.com/page2"></iframe>
</div>
<div class="iframediv">
    <iframe src="otherdomin.com/page"></iframe>
</div>

使用JQuery的hide或remove方法

<div class="iframediv" id="div1">
   <iframe src="otherdomin.com/page2" id="iframe1"></iframe>
</div>
<div class="iframediv" id="div2">
    <iframe src="otherdomin.com/page" id="iframe2"></iframe>
</div>
<script>
  $('#iframe1').click(function(){
     $('#div1').hide();
     //$('#div1').remove();
  });
</script>