I am trying to check and uncheck boxes when i am clicking through a series of divs. For example I have a list of three divs and each div correspond to one check box. When I select one div I should be checking a box and unchecking the box selected before with the previous click.
Here is my html
<div class="trigger">1</div>
<div class="trigger">2</div>
<div class="trigger">3</div>
<input id="one" type="checkbox">
<input id="two" type="checkbox">
<input id="three" type="checkbox">
and js
$('.trigger').click(function(){
$('input[type=checkbox]').attr('checked', false);
$('input[type=checkbox]').eq($(this).index('.trigger')).attr('checked', true);
});
The process runs fine for the first loop and stops working after the first iteration.But if i use .prop() instead of .attr(), it is working fine.
$('.trigger').click(function(){
$('input[type=checkbox]').prop('checked', false);
$('input[type=checkbox]').eq($(this).index('.trigger')).prop('checked', true);
});
can anybody explain the reason of this ??