you have a selector wrong it should be
$('#rmv')
and if you add an item dynamically, you should use it as
$(document).on('click','#rmv',function(e) {
your loop in the ajax callback will probably create elements with duplicate identifiers, which is wrong, as @Alnitak mentions that you can switch to the class selector, for example, after changing cde
$.getJSON('/api/v1/recipe/?format=json', function(data) { $.each(data.objects, function(i, recipe) { $('table#recipes').append('<tr><td>' + recipe.title + '</td><td>' + recipe.ingredients + '</td><td>' + recipe.method + '</td><td><button class="btn rmv" type="button" >remove</button></td></tr>'); }); });
and the selector will look like
$(document).on('click','.rmv',function(e) {
source share