Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loop through all td elements in a table

Tags:

jquery

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!

like image 970
user517406 Avatar asked Mar 04 '11 12:03

user517406


3 Answers

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

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

    // compare id to what you want
});
like image 177
alexn Avatar answered Nov 17 '22 07:11

alexn


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

then you can do a loop

like image 28
wong2 Avatar answered Nov 17 '22 09:11

wong2


$('#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

like image 2
TanvirChowdhury Avatar answered Nov 17 '22 08:11

TanvirChowdhury