JQuery toggle is hiding the div element

前端 未结 2 702
我在风中等你
我在风中等你 2021-01-22 08:55

I\'m having some trouble with developing an expand-shrink toggle div.

My goal is to click the div and make it bigger, clicking it again and get it back to the original h

相关标签:
2条回答
  • 2021-01-22 09:14

    jQuery toggle shows or hides an element, it doesn't toggle a function.

    To toggle height like you would like to, it would probably be best to introduce a new CSS class into your CSS file and use jQuery toggleClass to either add or remove the class. So:

    JS changes to this:

    $(document).ready(function () {
        $(".noticia").toggleClass('large');
    });
    

    CSS addition of class:

    .noticia.large {
        height: 600px;
    }
    
    0 讨论(0)
  • 2021-01-22 09:34

    toggle() (Event) event is deprecated in jQuery 1.8 and removed in jQuery 1.9.

    Current .toggle() function changes the state of the element.


    $(document).ready(function () {
        $(".noticia").click(function(){
            $(this).css('height', $(this).css('height') == "420px" ? "600px" : "420px");
        });
    });
    
    0 讨论(0)
提交回复
热议问题