For example, I want to checked/unchecked all item by <input type="checkbox" id="all" />. In my case, checked attribute is changed but it does not display (http://jsfiddle.net/Lvmy64w0/2/)
<form action="#">
<p>
<input type="checkbox" id="all" />
<label for="all">SelectAll</label>
</p>
<p>
<input class="item" type="checkbox" id="test5" />
<label for="test5">Red</label>
</p>
<p>
<input class="item" type="checkbox" id="test6" checked="checked" />
<label for="test6">Yellow</label>
</p>
<p>
<input type="checkbox" class="filled-in item" id="filled-in-box" checked="checked" />
<label for="filled-in-box">Filled in</label>
</p>
<p>
<input type="checkbox" id="test7" checked="checked" disabled="disabled" class="item" />
<label for="test7">Green</label>
</p>
<p>
<input type="checkbox" id="test8" disabled="disabled" class="item" />
<label for="test8">Brown</label>
</p>
</form>
$(function(){
$("#all").click(function () {
$('.item').attr('checked', this.checked);
});
});
Hello @uralbash
Try using prop, instead of attr:
$('.item').prop('checked', this.checked);
I have updated your fiddle so you can check it.
http://jsfiddle.net/Lvmy64w0/3/
For more information check this:
http://api.jquery.com/prop/
@Nohinn Thanks!
Most helpful comment
Hello @uralbash
Try using prop, instead of attr:
I have updated your fiddle so you can check it.
http://jsfiddle.net/Lvmy64w0/3/
For more information check this:
http://api.jquery.com/prop/