开发者

Using .each to iterate in table

开发者 https://www.devze.com 2023-03-29 17:09 出处:网络
I am trying to iterate through a table using the jquery .each function as such: $(\"#\" + tableID).each(function () {

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"));  
    } 
}); 
0

精彩评论

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

关注公众号