toggle show/hide div with button?

后端 未结 8 2013

Hopefully this is an easy question. I have a div that I want to toggle hidden/shown with a button

8条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 14:51

    Look at jQuery Toggle

    HTML:

    Hello World

    jQuery:

    jQuery(document).ready(function(){
        jQuery('#hideshow').live('click', function(event) {        
             jQuery('#content').toggle('show');
        });
    });
    

    For versions of jQuery 1.7 and newer use

    jQuery(document).ready(function(){
        jQuery('#hideshow').on('click', function(event) {        
            jQuery('#content').toggle('show');
        });
    });
    

    For reference, kindly check this demo

提交回复
热议问题