views:

385

answers:

2

Hey,

I have a jquery treeview as navigation for a website. I am using the options:

unique:true,
collapsed:true

but I need to have the first item expanded. I also would like to be able to toggle states in certain functions.

How can i programmatically toggle a jquery treeview item?

I have read the documentation and searched everywhere, but I can't figure it out. My javascript/jquery skills are not great, so I can't figure out how to add this feature myself.

Any help would be appreciated, thanks!

Update:

I spent so long looking at the options/source code I didn't see the "closed" class right there in the intro page. That helps a lot!

also, I found that using (pointed in the right direction by Chris Gutierrez):

$('#tree div.expandable-hitarea:first').click();

works to expand that item! Now, I just have to create my own toggle functions.

Thanks.

+1  A: 

The demo at the documentation link you provided, does exactly that. The source is available. Is there a problem with the way they do it there?

Sander Rijken
+1  A: 

It looks like you could just execute a click on the desired li. For the first one try something like

$("#example li.collapsable:first").click();

Or when you initially render the html, just add the "expandable" class to the first li.

Chris Gutierrez
this doesn't work for me, but it did help me figure it out (I've updated my question)
sieben
The css selector I used in the answer was setup for the example in the documentation. Glad you got it working.
Chris Gutierrez