I append a dynamic button and want when I click button Related data will be remove
async function DataShow()
{
for (i = 0; i < localStorage.length; i++)
{
x = localStorage.key(i);
if (x !='debugbar-time-new' && x !='debugbar-time' && x!='__mycart')
{
item = await JSON.parse(localStorage.getItem(x))
$("#table_data").append('<tr> <td>'+item['_id']+'</td> <td>'+item['title']+'</td><td><button class="btn btn-primary remove" value="'+item['_id']+'">remove</button></td></tr>')
}
}
}
there is my remove functionality
$( "#table_data" ).on('click','.remove',function(){
var item_id = $('#table_data button').val()
window.localStorage.removeItem(item_id);
});
Problem is when I click button Button always fetch last element id
I also see with inspect element all button have it's own id
I also try $('this').val()
but it not working
question from:
https://stackoverflow.com/questions/65870076/remove-appended-data-with-button-click-id-by-id 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…