Switch/toggle div (jQuery)

后端 未结 9 643
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 09:39

I wish to accomplish a fairly simple task (I hope!)

I got two div tags and one anchor tags, like this:

forgot p         


        
9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 10:24

    I think this works:

    $(document).ready(function(){
    
        // Hide (collapse) the toggle containers on load
        $(".toggle_container").hide();
    
        // Switch the "Open" and "Close" state per click then 
        // slide up/down (depending on open/close state)
        $("h2.trigger").click(function(){
            $(this).toggleClass("active").next().slideToggle("slow");
            return false; // Prevent the browser jump to the link anchor
        });
    });
    

提交回复
热议问题