Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get all TD data upon clicking on a TR with Jquery

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

like image 921
KillerFish Avatar asked Feb 24 '11 06:02

KillerFish


1 Answers

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);
    });

});
like image 89
SadullahCeran Avatar answered Oct 22 '22 09:10

SadullahCeran