jQuery Toggle Help

Posted by Cameron on Stack Overflow See other posts from Stack Overflow or by Cameron
Published on 2010-03-29T13:38:29Z Indexed on 2010/03/29 13:43 UTC
Read the original article Hit count: 166

Filed under:

I have the following code:

$(document).ready(function() {


  // Manage sidebar category display
  jQuery("#categories > ul > li.cat-item").each(function(){
    var item;
    if ( jQuery(this).has("ul").length ) {   
      item = jQuery("<span class='plus'>+</span>").click(function(e){
        jQuery(this)
          .text( jQuery(this).text() === "+" ? "-" : "+" )
          .parent().next().toggle();
        return false;
      });

      jQuery(this).find(".children").hide();
    } else {
      item = jQuery("<span class='plus'>&nbsp;</span>");
    }

    jQuery(this).children("a").prepend( item );
  });

});

This creates a sort of toggle system for my categories. But it will only work with 2 levels deep, what I need it to do is work with unlimited levels.

© Stack Overflow or respective owner

Related posts about jQuery