How to hide a iframe upon clicking on it with Jquery

家住魔仙堡 提交于 2020-01-06 19:48:13

问题


How to hide a iframe with jquery. When user click on iframe (example iframe containing a google ADD ) it should hide without disturbing the iframe code. How can i achieve this with Jquery.

Thank You


回答1:


I would have a link with id "toggle" right outside the iframe (on your page):

<a href="javascript:void(0);" id="toggle">-<span style="display:none">+</span></a>

Here's how you would link that up to hide the ad using jquery:

<script type="text/javascript">
    $(function(){
     var toggler=$("#toggle");
     toggler.click(function(){
      $("iframe").slideToggle('slow', function(){
         // or specify a specific iframe using $("#iframe_id")
        $("#toggle span").toggle();
      });
     });
    }); 
</script>


来源:https://stackoverflow.com/questions/4835904/how-to-hide-a-iframe-upon-clicking-on-it-with-jquery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!