开发者

CSS / JQuery - Filtering Table Rows and Inverting the Selection

I have a table with a number of rows, I then want to highlight the rows that contain 开发者_JAVA百科value x and then invert the selection.

So far I am able to select the rows that contains the filter value but inverting it is giving me problems.

First I am selecting the rows that match my search value and add a class name:

var rows = $("#table tbody tr td:nth-child(1):contains('" + searchValue + "')");
$(rows).parent().addClass('filtered');

Then I am trying to add a class name that doesn't have the 'filtered' class name, this is the line that I just cant get right:

$('#table tbody tr:not(.filtered)').addClass('hidden');   

The class hidden ends up on all rows.

Anyone got any ideas?

Thanks,

Martin


I tried it: http://jsfiddle.net/eYRWj/ it doesn't. It works as expected.

Try console.log(rows) (with firebug installed and its console enabled), to see if they are really marked as .filtered, i.e. if the search succeeded.


try with double quotes like this: $('#table tbody tr:not(".filtered")').addClass('hidden');

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜