endurain
6/4/2019 - 7:36 PM

An elegant collapse system for ul/li elements See the fiddle here https://jsfiddle.net/ufb9q3n3/ Essentially, plug in the jQuery script b

An elegant collapse system for ul/li elements

See the fiddle here https://jsfiddle.net/ufb9q3n3/

Essentially, plug in the jQuery script below, add CSS and away you go. The list you're looking to set this up on must be properly setup. ul>li>ul etc.

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

//apply this CSS (consider targeting to page/template)
 ul>li>ul {
    	display: none;
    }

//if necessary, wrap in this:
jQuery(document).ready(function($){
  
});