I am having a table with multiple rows and i want to get all the TD data after clicking on a particular ROW.
My Table is
<table>
<tr class="person">
<td class="id">1900</td>
<td class="name">John</td>
<td class="gender">Male</td>
</tr>
<tr class="person">
<td class="id">2000</td>
<td class="name">Pitt</td>
<td class="gender">Female</td>
</tr>
</table>
How can i Get id, name, gender after clicking on Row using Jquery.
Ex: If i click on John Row i should get 1900, John, Male and same for Pitt also
Thank You
Here is the solution. You may try find() method instead of children()
$(function(){
$('.person').click(function(){
var id = $(this).children('.id').text();
var name= $(this).children('.name').text();
var gender = $(this).children('.gender').text();
alert('Selected ID: ' + id + ', Name: ' + name + ', Gender: ' + gender);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With