tags:

views:

28

answers:

3

I have a html table and I need to get the first row's (which is not the thead part.It will be in tbody part) last columns value or text. I need the value on clicking the button btnAdd

 <table>
    <thead>
    <tr>
    <td>Name</td>
    <td>ID</td>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>Edwin</td>
    <td><span style='display:none'>1</span></td>
    </tr>
    </tbody>
    </table>
   <input type='btnAdd' runat='server' >
+2  A: 
$('table tbody tr:first td:last').text()
Ninja Dude
Wouldn't that select the last cell of the first row? Which is the one inside the `thead`?
David Thomas
I am accessing using ID ? SO can i use #tbl instead of table? #tbl is my table;s ID
Vishnu K B
@hari yes, you can !
Ninja Dude
thanks All i done by using $(#tableID).html()
Vishnu K B
A: 

This should work, I think:

$('btnAdd').click(
    function(){
       var text = $('tbody > tr:first > td:last').text();
    });
David Thomas
A: 
$("button").click(function(){
   var columnText = $("TABLE TBODY TR:first TD:last").html();
}
Chinmayee