+1 vote
1.3k views
in Programming by (390 points)
I am trying to get click event in li using jstree please see the code

$('#uu').click(function () {
var ref = $('#tree').jstree(true),
    sel = ref.get_selected();

if (!sel.length) {
    alert('thank')
    sel = ref.create_node("#", {"id" : node_count+1, "text" : node_count+1});
    node_count++;
} else
{
    sel = sel[0];
    sel = ref.create_node(sel, {"id" : node_count+1, "text" : node_count+1});
    node_count++;
}
/*if (sel) {
    ref.edit(sel);
}*/
ref.deselect_all();
});

Here in alert id of click event is not coming please help me out on this.
closed

1 Answer

+2 votes
by (1.4k points)
selected by
 
Best answer
As here your li is coming dynamically, so you should get id like this , I hope this will help you.

$("#tree").on("click", "li > a", function() {
    var id = $(this).closest("li").attr("id");
    $(this).siblings(".jstree-icon").click();
    alert(id);
});

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated