title: Collapsible list using JQuery
body: <pre><code>    &lt;script&gt;   
       $(document).ready(function(){
             var xml = "&lt;root&gt; \
                  &lt;method name='A'&gt; \
                  &lt;childcall name='B'&gt;&lt;/childcall&gt; \
                  &lt;childcall name='C'&gt;&lt;/childcall&gt; \
                  &lt;/method&gt; \
                  &lt;method name='B'&gt; \
                  &lt;childcall name='D'&gt;&lt;/childcall&gt; \
                  &lt;/method&gt; \
                  &lt;method name='C'&gt; \
                  &lt;childcall name='D'&gt;&lt;/childcall&gt; \
                  &lt;childcall name='E'&gt;&lt;/childcall&gt; \
                  &lt;/method&gt; \
                  &lt;/root&gt;";
  
              var data = $.parseXML(xml);
              console.log(data);
              $(data).find('method').each(function(){
                  var name = $(this).attr('name');
                  $('&lt;div class="items"&gt;&lt;/div&gt;').html('&lt;a href="'+name+'"&gt;'+name+'&lt;/a&gt;').appendTo('#page-wrap');
                  $(this).children('childcall').each(function(){
                      name = $(this).attr('name');
                      $('&lt;div class="items"&gt;&lt;/div&gt;').html('&lt;a href="'+name+'"&gt;'+name+'&lt;/a&gt;').appendTo('#page-wrap');
                  });
               });
        });
  
        &lt;/script&gt;
  &lt;body&gt;
      &lt;div id="page-wrap"&gt;&lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>The above code traverses the xml and prints items as - A B C B D C D E.
  I want to make this a collapsible list, like in the given link: <a href="http://www.sendesignz.com/index.php/jquery/77-how-to-create-expand-and-collapse-list-item-using-jquery" rel="nofollow">http://www.sendesignz.com/index.php/jquery/77-how-to-create-expand-and-collapse-list-item-using-jquery</a></p>
  
  <p>Any hint on how to make it collapsible?</p>
  
  <p>EDIT: Thanks for help. Sorry I cannot accept more than one answer as correct. So Shikiryu solution is also correct.</p>