user517406
user517406

Reputation: 13773

loop through all td elements in a table

How would I loop through all the td elements in a table? I need to find the id of each td and compare it against a value. Any help would really be appreciated!

Upvotes: 19

Views: 79662

Answers (3)

TanvirChowdhury
TanvirChowdhury

Reputation: 2445

$('#tableId').find('tr').each(function () {
 $(this).find("td[id^='tdId']").each(function (i, item) {
      //do your task here
        });
 });

Or the effective one is get all the tds from table first

var totalTdsInTable = $("#table-id td");

Now loop through totalTdsInTable

Upvotes: 3

wong2
wong2

Reputation: 35720

var all_td_in_a_table = $("#table-id td"),

then you can do a loop

Upvotes: 6

alexn
alexn

Reputation: 58962

Use jQuery.each to loop all your td's:

$("td").each(function() {
    var id = $(this).attr("id");

    // compare id to what you want
});

Upvotes: 38

Related Questions