I’m having an issue with getting the jquery filter method to work.
If I have
$("#resultDiv tr:odd").addClass("alternate_row");
All of the rows within the div “resultDiv” that contains a table are given the alternate row class.
However if i use
$('#resultDiv').filter("tr:odd").addClass("alternate_row");
It doesn’t appear to match any elements and nothing has the class applied.
I need to use the filter method as I’m doing a few other things passing variables around.
What am I missing?
In your first version:
.filter()removes non-matching elements from a set, and none of your#resultDivelements aretr, so the filter doesn’t match anything.Try:
which explicitly adds new descendent nodes that match the
tr:oddselector, orwhich uses a single selector to find all
trelements, and then uses.filterto only pick the odd ones.