需要JQuery帮助选择表行数组(tr)

时间:2011-03-29 05:04:10

标签: javascript jquery jquery-selectors

以下是代码段:http://jsbin.com/ekupa3/2/edit

我需要返回没有'test2'标签的表行(tr)。 输出应该是表行(tr)的数组。

我花了几个小时尝试我所知道的每一种JQuery技术,我会向专家们倾诉。

2 个答案:

答案 0 :(得分:3)

var newTag = 'test2';
var rows_without_newTag = $("table tr").not(":contains(" + newTag + ")");

Created an edit of the OP's JS Bin w /后代的一些示例用法。

答案 1 :(得分:1)

var newTag = 'test2',
    $tr = $('tr').filter(function() {
        return $(this).html().indexOf('>' + newTag + '</a>') == -1;
    });

$tr将是一个jQuery元素数组,其中包含不包含标记tr的所有test2。我在indexOf检查中包含了部分HTML,以防有另一个名为“another-test2”的标记等。

See example →