Dead simple Collapsable List Function for deep and shallow nested UL/LI lists (JQuery)

前端 未结 1 912
天命终不由人
天命终不由人 2020-12-07 03:02

I waded through a TON of terrible js \"solutions\" for how to simply make collapsible nested list(s).

This is what I eventually came up with.

相关标签:
1条回答
  • 2020-12-07 03:25

    css:

    ul>li>ul {
        display: none;
    }
    

    js/jquery

    $('li').click(function(e){
        e.stopPropagation();
        if(this.getElementsByTagName("ul")[0].style.display =="block")
            $(this).find("ul").slideUp();
        else
            $(this).children(":first").slideDown();
    });
    

    jfiddle

    0 讨论(0)
提交回复
热议问题