Removing multiple table cells from a specific row

I want to remove several table cells from a row, and I have an array that stores the indexes of the table cells that need to be deleted. But he only deleted the alternative cells. I have little knowledge in the request.

Here is my code.

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.

+4
source share
1 answer

You can try this without any loop .each(), but for this you should use this method:

$('yortblID/Class td:eq('+ before_lunchstart_array[count] +')').remove();

I think you are checking the index with the count index in the array before_lunchstart_array, so instead you can do it with help .eq()starting at 0, but still it will remove all those tds that are index === before_lunchstart_array[count].

So .eq(before_lunchstart_array[count]) index === before_lunchstart_array[count].

+1

Source: https://habr.com/ru/post/1536048/


All Articles