Simple menu with sub-levels 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 &gt; li.expand');
    $li.click(function(){
        $ul = $(this).find('ul.sub-level').delay(200).slideDown(400);
        $(this).removeClass('expand').addClass('minus');
        $('#main &gt; li &gt; ul').not($ul).slideUp('slow');
        $('#main &gt; li.minus').not($(this)).removeClass('minus').addClass('expand');

    })

    $li2 = $('.sub-level &gt; li.expand');
    $li2.click(function(){
        $(this).find('ul.sub-level2').delay(200).slideToggle(400);
        $li2.toggleClass('minus').toggleClass('expand');
    })      
});


HTML:

&lt;ul id="main"&gt;
&lt;li class="expand"&gt;test-1
&lt;ul class="sub-level"&gt;
    &lt;li class="expand"&gt;sub-test-1
        &lt;ul class="sub-level2"&gt;
            &lt;li&gt;sfasfasf&lt;/li&gt;
            &lt;li&gt;sfafasf&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;test-2&lt;/li&gt;
  &lt;li class="expand"&gt;test-3
  &lt;ul class="sub-level"&gt;
    &lt;li&gt;sub-test-2&lt;/li&gt;
    &lt;/ul&gt;
   &lt;/li&gt;
   &lt;li&gt;test-4&lt;/li&gt;
   &lt;/ul&gt;
Some suggestions:


Use var when declaring variables, unless you really want to make global variables (which you probably don't)
Combine var statements using ,

var a = 1, b = 2, c = 3;

Combine classes in toggleClass

$(this).toggleClass('minus expand')

Cache selectors that are used often (like $('#main'))
You don't need to use $li2 inside the click handler, you can just use $(this)
Turn repeated code into a function




$(function(){
    var $main = ('#main'),
    slide = function(ele, find){
        return $(ele).toggleClass('minus expand').find(find).delay(200).slideToggle(400);
    },
    $li = $('&gt; li.expand', $main).click(function(){
        var $ul = slide(this, 'ul.sub-level');
        $('&gt; li &gt; ul', $main).not($ul).slideUp('slow');
        $('&gt; li.minus', $main).not(this).toggleClass('minus expand')
    }),
    $li2 = $('.sub-level &gt; li.expand').click(function(){
       slide(this, 'ul.sub-level2');
    });
});