iterate table in jquery

Solutions on MaxInterview for iterate table in jquery by the best coders in the world

showing results for - "iterate table in jquery"
Yannik
09 Aug 2016
1
2$(".button").on('click', function () {
3
4                $("#myTable tr").each(function () {
5                    var self = $(this);
6                    var col_1_value = self.find("td:eq(0)").text().trim();
7                    var col_2_value = self.find("td:eq(1)").text().trim();
8                    var col_3_value = self.find("td:eq(2)").text().trim();
9                    var col_4_value = self.find("td:eq(3)").text().trim();
10                    var result = col_1_value + " - " + col_2_value + " - " + col_3_value + " - " + col_4_value;
11                    console.log(result);
12                });
13            });
Kayla
02 May 2017
1
2<table id="myTable" style="margin-left:50px;">
3  <tr><th>Sr no</th><th>Name</th><th>Gender</th><th>Location</th></tr>
4  <tr><td> 1</td><td>Satinder Singh</td><td> M </td><td> India </td></tr>
5  <tr><td> 2 </td><td>Amit Sarna</td><td> M </td><td> France </td></tr>
6  <tr><td> 3 </td><td>Andrea Ely</td><td> F </td><td> Brazil </td></tr>
7  <tr><td> 4 </td><td>Leslie Mac </td><td> F </td><td> Australia </td></tr>
8  <tr><td> 5 </td><td>Sonya David </td><td> F </td><td>America</td></tr>
9</table>
10