I am using the JQuery Treeview plugin to display some data. Basically, I would like to add a click event to the child < li > elements that copies their innerhtml into another div on the page. I have not been able to assign a click event to these < li > elements however.
Hoping someone has tread this ground before and can provide some help.
Thanks.
Using the markup from the example at http://docs.jquery.com/Plugins/Treeview:
$("span.file, span.folder", "#example li")
.click(function() { alert($(this).text()); });
works. Handling the click on the LI items themselves captures branch contractions and expansion.
You can use .live construction. For me it works:
$('li','ul#menu').live('click', function(){
alert('Click event');
});
<li onclick="selectNode(event, this);" id="${node2.nodeId}" class="closed">
<span class="folder"> ${node2.name} </span>
</li>
function selectNode(event, nodeHtmlEl) {
// IE
if ($.browser.msie) {
window.event.cancelBubble = true;
}
if(event.stopPropagation) {
event.stopPropagation();
}
alert("selectNode ID: " + $(nodeHtmlEl).attr("id"));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With