I have created a table:
---------------------------
| 22 | 23 | Select |
|-------|-------|---------|
| NY | CA | (button)|
| Miami |Dallas | (button)|
using:
<table class="table table-bordered">
<thead>
<tr>
<th><?php echo implode('</th><th>', array_keys(current($filtered_cur_result))); ?></th><th>Select</th>
</tr>
</thead>
<tbody>
<?php foreach ($filtered_cur_result as $row): array_map('htmlentities', $row); ?>
<tr>
<td><?php echo implode('</td><td>', $row); ?></td><td><button type="button" name="update" id="update" class="update btn btn-success btn-xs">Update</button></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Now on click on the button of the row I want table header and row data.For example:
- If I select first button then I want: 22 NY 23 CA
- If select second button then I want: 22 Miami 23 Dallas
My code is:
$(document).one('click', '.update', function() {
var $row = $(this).closest("tr"),
$tds = $row.find("td");
$.each($tds, function() {
console.log($(this).text());
});
});
But I am getting only rows. Like:
NY
CA
Highly appreciate your suggestion.