Javascript 关于删除包含所有<;td>;有一个特定的类

Javascript 关于删除包含所有<;td>;有一个特定的类,javascript,jquery,Javascript,Jquery,您能看一下并告诉我如何只删除,所有都有.old类吗 我试过这个代码来做这项工作 $("#removeOld").on("click",function(){ $('tbody').find('tr').each(function () { var rows = 0; var rows_old = 0; $(this).find('td').each(function () { rows++; if ($(this).has('old

您能看一下并告诉我如何只删除
,所有
都有
.old
类吗

我试过这个代码来做这项工作

$("#removeOld").on("click",function(){
  $('tbody').find('tr').each(function () {

    var rows = 0;
    var rows_old = 0;

    $(this).find('td').each(function () {
        rows++;
        if ($(this).has('old')) rows_old++;
    });

    if (rows === rows_old) $(this).remove();
});
});
但这是在移除整张桌子!你能让我知道我做错了什么,以及如何解决这个问题吗


谢谢

您需要删除
tr
中没有
td
td.old
所以

$(“#移除旧”)。在(“单击”,函数(){
$('tbody tr').not(':has(td:not(.old))).remove()
});

删除整个旧行!
一些旧的
史密斯
50
全新的
杰克逊
94
一些旧的
史密斯
50
老
史密斯
50

.hasClass()
而不是
.has()
。帮助阅读文档。虽然如果只执行
if(this.cells.length==$(this.find(“td.old”).length)$(this.remove(),会更简单请在问题中包含HTML。