Using .each to iterate in table
I am trying to iterate through a table using the jquery .each function as such:
$("#" + tableID).each(function () {
if ($("#" + this).hasClass ('notSelected')) {
selected ($("#" + this).attr ('id'));
}
});
Basically I want to go through each row. Send the id of开发者_StackOverflow中文版 that row to a function called selected. I am getting a syntax error. Not sure what I'm doing wrong.
Thanks.
Currently, your code is attempting to loop through each element on the page that has an ID that matches the value of the tableID
variable. Append the tr
selector to your existing selector to loop through each row. Also, since you're using the tr
selector, $(this)
inside of the loop refers to the jQuery row object.
$("#" + tableID + " tr").each(function () {
if ($(this).hasClass("notSelected")) {
selected($(this).attr("id"));
}
});
精彩评论