i have list of items, i need to set checkbox checked value to true when price input is empty, and to false when it's not.
<td><input type="text" value="" class="name"></td>
<td><input type="text" value="" class="producer"></td>
<td><input type="text" value="" class="model"></td>
<td><input type="text" value="" class="dateOf"></td>
<td><input type="text" value="" class="color"></td>
<td><input type="text" value="" class="price"></td>
Edit:
<td><input type="checkbox" class="checkbox"></td>
and there is my jquery function :
$(function() {
$('.price').on('input', function() {
if (!$('.price').val()) {
$(this).closest('td').next().find('.checkbox').prop("checked", true);
}else{
$(this).closest('td').next().find('.checkbox').prop("checked", false);
}
});
});
the problem is that it works only for first "price" input, how to make it work for all ?
this. To turn the DOM element into a jQuery object that we can use jQuery methods on, we simply do$( this )". Tutorials are great, they help a lot! You should read them!$(this).closest('td').next().find('.checkbox').prop("checked", !$(this).val());(and remove the if/else statement)