Reputation: 141
currently I am using the following code to remove a row of data within a table from HTML5 local storage:
$("#deletedata").click(function() {
var itemId = $("input:checked").parent().parent().attr('id');
localStorage.removeItem(itemId);
});
Basically I have a checkbox within each row, when this is checked and the 'delete selected' button is pressed this bit of code targets the parent row holding the data. It works fine, however it doesn't work if multiple rows are selected - it will only remove the first row it finds from localstorage. I need the 'delete selected' button to remove ALL selected rows.
Can anyone help with this? Thanks!
Upvotes: 1
Views: 1123
Reputation: 4076
Try using .each()
to get all input checked, and delete the item in the local storage:
$("#deletedata").click(function() {
$("input:checked").each(function(){
var itemId = $(this).parent().parent().attr('id');
localStorage.removeItem(itemId);
});
});
In your code only get the first and delete.
Upvotes: 1