Reputation: 91
How can I write Javascript to expand and collapse a particular parent of a TreeView
when i click on the parent node?
If one of the parent nodes is expanded, then if I click on that it should collapse; and if already collapsed, then vice versa.
Upvotes: 1
Views: 674
Reputation: 22438
It's as easy as:
<ul id="tree">
<li>
<span class="title">Title</span>
<ul>
<li><span class="title">Item 1</span></li>
<li><span class="title">Item 2</span></li>
<li><span class="title">Another item</span>
<ul>
<li><span class="title">another one</span></li>
</ul>
</li>
</ul>
</li>
</ul>
$(document).ready(function(){
$('#tree span.title').click(function(){
$(this).next().toggle();
});
});
When using jQuery.
Upvotes: 3