kbvishnu
kbvishnu

Reputation: 15630

How to get the first row's last column of an Html table using jQuery

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' >

Upvotes: 2

Views: 6229

Answers (3)

Chinmayee G
Chinmayee G

Reputation: 8117

$("button").click(function(){
   var columnText = $("TABLE TBODY TR:first TD:last").html();
}

Upvotes: 0

David Thomas
David Thomas

Reputation: 253308

This should work, I think:

$('btnAdd').click(
    function(){
       var text = $('tbody > tr:first > td:last').text();
    });

Upvotes: 1

user372551
user372551

Reputation:

$('table tbody tr:first td:last').text()

Upvotes: 5

Related Questions