I am using the jQuery Treeview plugin. Have a look to the "Sample 1 - default" provided on the demo page of the plugin In my case all folders and files are links. If I click for example on the expanded "Folder 2" it will first collapse and then follow to the link location. The behaviour I would like to is, that only collapsed ones will expand first and if it already expanded it will stay like this.

The code in the plugin (jquery.treeview.js) which toggle the behaviour is the following:

66 this.filter(":has(>ul):not(:has(>a))").find(">span").click(function(event) {
67 toggler.apply($(this).next());
68 }).add( $("a", this) ).hoverClass(); 

I already figured out how to get all the links, which should be changed:


The result will be a array of all li which are currently collapsable (expanded): [li., li.collapsable]

But I don't know how to proceed from there :-( Hopefully someone could help me along...

I already changed sucessfully the linkbehavior for the current selected (class=selected) link with this code:


Many thanks in advance!

No correct solution


maybe it was not clear what I really want to do so I will try to improve my verbalization next time ;-)

The answer to my own question is:


Maybe it helps someone who is looking for something similar.

Best regards!!

UPDATE (the posted solution above does not work if the user expanded a node without reloading the page after)

        if ($(this).is('.current')) {
        } else if ($(this).parent().parent().is('.collapsable')) {

This one works as it it supposed to. :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow