Kelsey Kelsey - 4 months ago 10x
jQuery Question

How to get ID of 3rd Previous Input Type Time Once Button is Clicked

I have got the following inputs like so:

<tr><td><input type='time' id='32'></td><td><input type='text'></td></tr>
<tr><td><input type='time'></td><td><input type='time' ></td><td><button class='clicker'>Get ID</button></td></tr>

When I click the button I want Jquery or JS to alert me the ID in the 3rd previous input (where type=time), which is "32".

I have tried the following code:


However, I keep getting "undefined".

Any ideas?


You can do it like following.

$('.clicker').click(function() {
<script src=""></script>
        <td><input type='time' id='32'></td>
        <td><input type='text'></td>
        <td><input type='time'></td>
        <td><input type='time'></td>
        <td><button class='clicker'>Get ID</button></td>