javascript - Detect th value from table click -


<table>     <thead>          <tr>             <th>name</th>             <th>address</th>         </tr>     </thead>      <tbody>         <tr>             <td>bob</td>             <td>300 wacker drive</td>         </tr>     </tbody> </table> 

if click on bob, want value "name". how can using jquery?

yes. on click of td

var thval = $(this).closest('table').find('th').eq( this.cellindex).text(); alert(thval); 

Comments