sieben
sieben

Reputation: 2201

Programmatically toggle a jquery treeview item?

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.

Upvotes: 2

Views: 3251

Answers (2)

Chris Gutierrez
Chris Gutierrez

Reputation: 4755

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.

Upvotes: 2

Sander Rijken
Sander Rijken

Reputation: 21615

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?

Upvotes: 1

Related Questions