Get cell value from string based on another cell value

enter image description here

I want to get the age of a specific name, I will say that I want to get the age of Garrett Winters using jquery. the record can be on any row of the table. I need to search the entire table and get the corresponding age in the variable.

I want to find the Name column for a specific value and get the appropriate age

<table id="table1" border="1" cellspacing="0" width="100%"> <thead> <tr> <th>Name</th> <th>Position</th> <th>Office</th> <th>Age</th> <th>Start date</th> <th>Status</th> </tr> </thead> <tfoot> <tr> <th>Name</th> <th>Position</th> <th>Office</th> <th>Age</th> <th>Start date</th> <th>Status</th> </tr> </tfoot> <tbody> <tr> <td>Tiger Nixon</td> <td>System Architect</td> <td>Edinburgh</td> <td>61</td> <td>2011/04/25</td> <td>CNF</td> </tr> <tr> <td>Garrett Winters</td> <td>Accountant</td> <td>Tokyo</td> <td>63</td> <td>2011/07/25</td> <td>CNF</td> </tr> <tr> <td>Ashton Cox</td> <td>Junior Technical Author</td> <td>San Francisco</td> <td>66</td> <td>2009/01/12</td> <td>CNF</td> </tr> <tr> <td>Cedric Kelly</td> <td>Senior Javascript Developer</td> <td>Edinburgh</td> <td>22</td> <td>2012/03/29</td> <td>TMP</td> </tr> <tr> <td>Airi Satou</td> <td>Accountant</td> <td>Tokyo</td> <td>33</td> <td>2008/11/28</td> <td>CNF</td> </tr> <tr> <td>Brielle Williamson</td> <td>Integration Specialist</td> <td>New York</td> <td>61</td> <td>2012/12/02</td> <td>TMP</td> </tr> </tbody> </table> 

im new for jquery. help me

+5
source share
2 answers

You can do something like this. It works for me. Demo

 $(document).ready(function(){ var nameToSearch ="Tiger Nixon"; $('table tr').each(function(){ if($(this).find('td').eq(0).text() == nameToSearch) alert("Age of "+nameToSearch+" is "+$(this).find('td').eq(3).text()); }); }); 

Hope this helps you.

+3
source

Use :contains Psudeo selector in jquery. Get Age From Garrett Winters

 var serachName = 'Garrett Winters'; $("table tbody tr td:contains("+serachName+")").parent().find('td:eq(3)').text() 

Fiddle

+3
source

All Articles