I am trying to get it so that the previous checkbox is checked if one of the ones next to it is selected, for example…
I have a list of inputs like this:
<input class="options" type="checkbox" value="1" name="option[]">
<input class="inner_options" type="checkbox" value="1" name="inner_options[]">
<input class="inner_options" type="checkbox" value="2" name="inner_options[]">
<input class="options" type="checkbox" value="2" name="option[]">
<input class="inner_options" type="checkbox" value="3" name="inner_options[]">
<input class="inner_options" type="checkbox" value="4" name="inner_options[]">
and I want it so that if a user selects an inner_options checkbox then jquery will find the previous option and check it…if that makes sense?
I have this but it does not work:
$('.inner_options').click(function(){
$(this).prev('.options').attr('checked',true);
});
Any help would be greatly appreciated, thanks.
.prev()selects the element’s single previous sibling.You want
.prevAllto find all matching prior siblings.