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
2009-11-30 16:33:13
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
2009-11-30 16:51:28
Also, I am using the async treeview (lazy loading). Would this be a game changer? Sorry I should have mentionned that.
helios456
2009-11-30 16:53:58
I would also like to identify the node. Set a javascript variable with its ID
helios456
2009-11-30 16:55:21
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
2009-12-01 14:46:07