views:

236

answers:

3

I am using the JQuery TreeView plug-in and I would like a know how I can highlight/identify the last selected node. Has anyone run into this?

+1  A: 
$('ul.yourclassselected li:last-child').addClass( 'highlight class' );
Alexander Corotchi
Sorry, I am fairly new to JQuery. Where do I put this line? in the document ready? What do yourclassselected and highlighted class represent?
helios456
Also, I am using the async treeview (lazy loading). Would this be a game changer? Sorry I should have mentionned that.
helios456
I would also like to identify the node. Set a javascript variable with its ID
helios456
A: 

Did you figure this out? If so, what does the syntax look like?

TWR
A: 

As I did not receive an answer to my questions from Alexander Corotchi, I ended up implementing my own solution to the problem. I'm sure there are simpler solutions out there, but here it is.

 $(treeView).treeview({
        /* Initialize TreeView */
    }) 
 $(treeView).click(function onTreeViewClick(sender) {
        var clickedElement = $(sender.target);
        if (clickedElement.hasClass('hover')) {
            //Find all selected nodes and deselect them.
            var treeView = $(document.getElementById('usxTreeView'));
            $.each(treeView.find(".selectedNode"), function(index, node) {
                $(node).removeClass('selectedNode');
            });
            //Select newly selected node
            clickedElement.addClass('selectedNode');
            //Get the node Id for the parent LI
            var parents = clickedElement.parent('li');               
            //This can then be used to identify the node.
            selectedTreeNodeId = parents[0].id; 
        }
    });
helios456