toggle show/hide div with button?

后端 未结 8 1916

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:

    <div id='content'>Hello World</div>
    <input type='button' id='hideshow' value='hide/show'>
    

    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

    0 讨论(0)
  • 2020-11-22 15:00
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
    $('#hideshow').click(function(){
        $('#content').toggle('show');
      });
    });
    </script>
    

    And the html

    <div id='content'>Hello World</div>
    <input type='button' id='hideshow' value='hide/show'>
    
    0 讨论(0)
提交回复
热议问题