Using JQuery to toggle div visibility

前端 未结 4 1853
粉色の甜心
粉色の甜心 2021-01-12 13:10

I\'m writing some jquery code to toggle a Div visibility. I followed the method posted here: http://jsfiddle.net/Ga7Jv/.

When the user clicks an image (next to a H2

4条回答
  •  死守一世寂寞
    2021-01-12 13:37

    Problem with your code is that its last function call is .hide(), thus it will always hide the div

    Simply use .toggle(), it display or hide the matched elements.

    $(function(){
        $('.expander').live('click',function(){
            $('#TableData').toggle();
        });
    });
    

    Fiddle

    OR

    $(function () {
        $('.expander').live('click', function () {
            $('#TableData').slideToggle();
        });
    });
    

    Fiddle with slide

    You can use .slideToggle(), if you want to display or hide the matched elements with a sliding motion

提交回复
热议问题