JQuery toggle is hiding the div element

前端 未结 2 727
我在风中等你
我在风中等你 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;
    }
    

提交回复
热议问题