Q:

Index of a dynamic created list Javascript

i have a dynamically created list with data of a json. 
So my question is how to get the index of a clicked item.  
I tried this: 
$("li").click(function() {
       var index = $("li").index(this);
       alert(index); });

But this didnt work.  I dont get an alert?  
If i create some static Li elements, i get the index of them.  
Please help me :/ 

A:

Dynamically created lists will require delegated events...
$("ul").on("click", "li", function() {
       var index = $(this).index();
       alert(index);
});

If the <ul> is also dynamically created, please select a parent node that exists before the list is created.