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

I wandered through TON from terrible js "solutions" to just make dumpable nested lists.

Here's what I ended up with.

I am posting here in the hopes that the next guy will not deal with all the rufuse.

Otherwise, feel free to add your own! maybe a jquery free method if you can control it?

+3


source to share


1 answer


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

+4


source







All Articles