Answers for "how to loop through table tr in jquery"

1

jquery for each tr in td

// tr is the jquery object
$(tr).find('td').each (function (index, td) {
  console.log(td)
});

// for each tr get each td

$('#tableContent tr').each(function(index, tr) {
  $(tr).find('td').each (function (index, td) {
    console.log(td)
  });
});
Posted by: Guest on February-03-2021
0

iterate table in jquery

$(".button").on('click', function () {

                $("#myTable tr").each(function () {
                    var self = $(this);
                    var col_1_value = self.find("td:eq(0)").text().trim();
                    var col_2_value = self.find("td:eq(1)").text().trim();
                    var col_3_value = self.find("td:eq(2)").text().trim();
                    var col_4_value = self.find("td:eq(3)").text().trim();
                    var result = col_1_value + " - " + col_2_value + " - " + col_3_value + " - " + col_4_value;
                    console.log(result);
                });
            });
Posted by: Guest on January-29-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language