简体   繁体   中英

Delete multiple table cells from specific row

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.

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] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM