Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get table id by click in td using jQuery

I have a tr in a table header that contains several input fields.

Is there a way that by click on one of these input fields I can get the id of the parent table ?

My tr looks like this:

<table id="tableID">
    <thead>
        <tr>
            <th><input type="text" name="input1" id="input1" /></th>
            <th><input type="text" name="input2" id="input2" /></th>
            <th><input type="text" name="input3" id="input3" /></th>
        </tr>
    </thead>
    <tbody>
        // ...
    </tbody>
</table>
like image 575
user2571510 Avatar asked Nov 24 '13 14:11

user2571510


1 Answers

In the click handler you can use .closest()

$(this).closest('table').attr('id')

like image 83
Arun P Johny Avatar answered Oct 21 '22 01:10

Arun P Johny