user2504897
user2504897

Reputation: 19

select closest element - loop to first / traverse table

I have a table row of the following structure:

<tr>
<td><input type="checkbox" limit="one"></input></td>
<td><input type="checkbox" limit="one"></input></td>
</tr>

I need to find a way to target the next / closest input to the one that has been checked, and give it a .attr("disabled").

The issue I've got is that using closest simply targets the same element, and using next will not target the first element if the element being ticked is already the last one in the row.

Any and all help / nudges in the right direction are appreciated.

Upvotes: 0

Views: 118

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388336

Try

$('input').on('change', function() {
    $(this).closest('tr').find('input').not(this).prop('disabled', this.checked)
});

Demo: Fiddle

Upvotes: 1

Related Questions