<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script> <script type="text/javascript"> function test(){ var id = $(".use-address").closest("tr").find('td:eq(2)').text(); alert(id); } </script> </head> <body> <table id="choose-address-table" class="ui-widget ui-widget-content"> <thead> <tr class="ui-widget-header "> <th>Name/Nr.</th> <th>Street</th> <th>Town</th> <th>Postcode</th> <th>Country</th> <th>Options</th> </tr> </thead> <tbody> <tr> <td class="nr"><span>50</span> </td> <td>Some Street 1</td> <td>Glas</td> <td>G0 0XX</td> <td>United Kingdom</td> <td> <button type="button" class="use-address" onclick="test();">Use</button> </td> </tr> <tr> <td class="nr"><span>30</span> </td> <td>Some Street 2</td> <td>Glasgow</td> <td>G0 0XX</td> <td>United Kingdom</td> <td> <button type="button" class="use-address" onclick="test();">Use</button> </td> </tr> </tbody> </table> </body> </html>
Remove onclick function try this $("body").on('click', '.use-address', function() { $(this).parent().parent().children(':nth-child(2)').text(); });
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)