$(".item").on('click',function(){
alert($(this).text());
});
count=0;
$("#new").on('click',function(){
count++;
$li = $("<li class='item'>LI "+count+"</li>");
$("ul").find('.item').last().after($li);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<ul>
<li class='item'>LI 0</li>
<li id='new'>+ Adicionar li</li>
</ul>
I made a simple code above to demonstrate the problem in question.
As you can see, after a new <li>
element is added it does not inherit the click event that was set earlier in the
How could you make it inherit this event without having to go back every time a <li>
is added?