views:

39

answers:

1

how to write java script for expand and collapse particular parent of treeview when i click on the parent node... if one of parent node expand ,if i click on that it should be collopse,.... and if collapsed vics versa

+2  A: 

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.

Here is an example

Harmen
i need in javascript!!
jQuery is actually a Javascript library, which makes Javascript a little easier to write: http://jquery.com/
Harmen
can u pls provide in javascript because im totally new in javascript as well treeview