I need to loop though a table where the table rows contain either class1 or class2 , how to I go about doing this.
Tried the following, but not working
var trs = $("#emailTable tr");
trs.each(function(i,n){
var current = $(n+":has(.class1 .class2)").attr('class');
alert(cur开发者_开发技巧rent)
});
It can be done using the folllowing code:
$("#emailTable tr.class1, #emailTable tr.class2").each(function (ix, element) {
// Do your processing.
});
Simply enter a comma between the two classes in your selector.
$(".a, .b")
this will match all elements with class "a" OR class "b"
You should add logic to the selector so that it only takes the rows of the table you are interested in.
I think this will work
$('#table tr.class1,#table tr.class2').each(function(i, elem) {
...
});
The selector would be $(".class1,.class2")
.
精彩评论