In my html I have this code for the list-group:
<ul class="list-group" name="list-group" id="list-group">
I populate this list group via onclick method with this on my js: where a = value of a dropdown button;
$('#list-group').append('<li>' + a +'<button id="delete">delete</button></li>');
or
$('#list-group').append('<button type="button" id="delete" class="list-group-item list-group-item-action">' + a + '<span class="pull-right"><span class="glyphicon glyphicon-erase" aria-hidden="true"></span></span></button>');
How can I remove the appended list item dynamically? I tried to delete or remove it with this code:
$(".delete").on('click',function () {
$(this).closest("li").remove();
alert("clicked");
});
Thanks in advance!