How to hide a iframe upon clicking on it with Jque

2019-08-30 01:07发布

问题:

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>