Reputation: 170
I want to delete multiple table cells from a row, and I have an array which store the indexes of table cells to be deleted. But it deleted only alternative cells. I don't have much knowledge in query.
Here is My code is.
var current_row_id=$(this).parent()[0].id;
var row_elem=document.getElementById(current_row_id);
for(var count=0;count<before_lunchstart_array.length;count++) {
$('#'+current_row_id+' td').each (function(index) {
if(index==before_lunchstart_array[count]) {
$(this).remove();
}
});
}
Please help me.
Upvotes: 4
Views: 529
Reputation: 74738
You can try this without any .each()
loop but for this you have to use this way:
$('yortblID/Class td:eq('+ before_lunchstart_array[count] +')').remove();
I think you are checking for index with count index in before_lunchstart_array
array so instead you can do this with .eq()
its index start from 0, still it will remove all those tds which index === before_lunchstart_array[count]
.
So .eq(before_lunchstart_array[count])
is equal to index === before_lunchstart_array[count]
.
Upvotes: 1