Skip to content

Instantly share code, notes, and snippets.

@gbirke
Created February 8, 2012 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbirke/1770599 to your computer and use it in GitHub Desktop.
Save gbirke/1770599 to your computer and use it in GitHub Desktop.
jQuery lightweight tree
#container li {
line-height:18px;
}
#container li ins {
display: inline-block;
width:18px;
height:18px;
text-decoration:none;
background-image:url('images/d.png'); // sprite image from jsTree
background-repeat:no-repeat;
background-position:0px 0px;
}
#container li ins.open {
background-position:-18px 0px;
}
#container li ins.empty {
background-image:none;
}
jQuery('#container li').each(function() {
var elem = jQuery(this),
has_children = elem.children('ul').length,
toggler = '<ins class="'+(has_children ? "closed" : "empty")+'">&nbsp;</ins>'
;
elem.prepend(toggler);
});
jQuery('#container').on('click', 'ins', function(){
var ins = jQuery(this);
ins.toggleClass('open closed');
ins.siblings('ul').toggle();
});
jQuery('#container li ul').hide();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment