What I am trying to do is get the id name of newly added item in the list on click. Here's my code.
$(document).ready(function() {
$('ul>li').on('click', function() {
var idName = $(this).attr('id');
alert(idName);
});
$('#add').click(function() {
var n = Math.floor((Math.random() * 100) + 1);
$('ul').prepend('<li id="name-' + n + '">New Item</li>');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li id="name-88">Old Item</li>
<li id="name-59">Old Item</li>
<li id="name-48">Old Item</li>
</ul>
<button id="add">Add Item</button>