I am working on an app where i need to add users dynamically from UI and delete them if required.
Adding users is working fine but deleting i am finding it difficult. I tried to recreate the scenario in jsfiddle.net https://jsfiddle.net/ce236Lf3/
code
<input type="text" class="txtadd">
<button class="btnadd">
Add
</button>
<ul class="items">
</ul>
ul{
list-style:none;
}
.del{
cursor:pointer;
}
$(document).ready(function(){
$('.btnadd').click(function(e){
var txt=$('.txtadd').val();
$('.items').append('<li class=\'listItem\'>'+txt+'<img src=\'http://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/16/Actions-edit-delete-icon.png\' class=\'del\'></li>');
$('.txtadd').val('');
});
$('.del').on('click',function(e){
alert('hi');
$('this').remove();
});
})