可以选择与选择器不匹配的所有元素吗?

时间:2010-09-10 10:50:02

标签: javascript jquery css jquery-selectors

我有一张包含很多行的表。

我想选择与某个选择器不匹配的所有行。

例如:

$('#my_table tr').each(function() {
    if ($(this).find(".class_a.class_b[my_param='" + my_value + "']").length > 0) {
        $(this).do_something();
    }
});

是否可以更容易地做同样的事情?

2 个答案:

答案 0 :(得分:5)

看一下jQuery的:not()-selector。它排除了当前选择集中的元素。

答案 1 :(得分:0)

$('#my_table tr').not('.class_a').each(function(){
   // do something
}
);

上面的代码将选择ID =' my_table '并且其类名不是“ class_a ”的表格中的所有行。这是你需要的吗?

相关问题