Here is an example of what I am trying to accomplish, except that it uses lists (UL and LI): http://homework.nwsnet.de/news/ea21_turn-nested-lists-into-a-collapsible-tree-with-jquery
My data is structured using DL, DT and DD tags, like this:
<dl>
<dt>Root</dt>
<dd>
<dl>
<dt>Coffee</dt>
<dd>black hot drink</dd>
<dt>Milk</dt>
<dd>white cold drink</dd>
<dt>Beer</dt>
<dd>
<dl>
<dt>European</dt>
<dd>Heineken</dd>
<dt>Mexican</dt>
<dd>Corona</dd>
</dl>
</dd>
</dl>
</dd>
</dl>
How can I use jQuery to turn each DT (and its corresponding DD content) into a collapsible/expandable node, ie a treeview?
At it's most basic, you can simply use
toggle
with theclick
event handler to do this:You will, of course, want to use
toggleClass
to add additional styles as appropriately, as well as other effects. See: http://www.jsfiddle.net/yijiang/EA4R5/1/The man himself John Resig has already a video explaning how to create such menu using DL, DT and DD tags. Check out: