Reputation: 12411
In the jsfiddle
CODE:
<script type="text/javascript">
function checkAll() {
var checked = $("#checkAll").is(':checked');
$(".check_row").attr("checked", checked);
}
</script>
<div>
<input type="checkbox" id="checkAll" onclick="checkAll()" />Check All <br />
<input type="checkbox" class="check_row" />One <br />
<input type="checkbox" class="check_row" />Two <br />
<input type="checkbox" class="check_row" />Three <br />
<input type="checkbox" class="check_row" />Four <br />
<input type="checkbox" class="check_row" />Five <br />
<input type="checkbox" class="check_row" />Six <br />
</div>
"check all" checkbox works for only first time. Can someone help me to find out what is wrong happening?
Upvotes: 0
Views: 711
Reputation: 5896
attr
to prop
in thisvar checked
function checkAll() {
checked = $("#checkAll").is(':checked');
$(".check_row").prop("checked", checked);
}
$('#checkAll').on('change',function(){
$(".check_row").prop("checked", $(this).is(':checked'));
});
Upvotes: 2
Reputation: 4495
function checkAll()
{
var checked = $("#checkAll").is(':checked');
$(".check_row").prop("checked", true);
if(!checked)
{
$(".check_row").removeAttr("checked");
}
}
Upvotes: 0
Reputation: 993
change this line
$(".check_row").attr("checked", checked);
to
$(".check_row").attr("checked", true);
Fiddle : http://jsfiddle.net/auXdC/5/
Upvotes: 0
Reputation: 20834
$('#checkAll').on('change',function(){
if($(this).is(':checked')){
$(".check_row").prop("checked", true);
}
else{
$(".check_row").prop("checked", false);
}
});
Upvotes: 1