Reputation: 707
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 that row to a function called selected. I am getting a syntax error. Not sure what I'm doing wrong.
Thanks.
Upvotes: 2
Views: 167
Reputation: 61793
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"));
}
});
Upvotes: 5