The following works as intended, however is there a more concise way to write this script without changing it too much? It's a simple menu with sub-levels which have a plus/minus icon when each li
opens/closes.
jQuery:
$(document).ready(function() {
$li = $('#main > li.expand');
$li.click(function(){
$ul = $(this).find('ul.sub-level').delay(200).slideDown(400);
$(this).removeClass('expand').addClass('minus');
$('#main > li > ul').not($ul).slideUp('slow');
$('#main > li.minus').not($(this)).removeClass('minus').addClass('expand');
})
$li2 = $('.sub-level > li.expand');
$li2.click(function(){
$(this).find('ul.sub-level2').delay(200).slideToggle(400);
$li2.toggleClass('minus').toggleClass('expand');
})
});
HTML:
<ul id="main">
<li class="expand">test-1
<ul class="sub-level">
<li class="expand">sub-test-1
<ul class="sub-level2">
<li>sfasfasf</li>
<li>sfafasf</li>
</ul>
</li>
</ul>
</li>
<li>test-2</li>
<li class="expand">test-3
<ul class="sub-level">
<li>sub-test-2</li>
</ul>
</li>
<li>test-4</li>
</ul>
var
before your variables. \$\endgroup\$