I want to select all checkbox
elements expect disabled ones,
this is my html
It can be as short as
$('#chkSelectAll').click(function() {
$('div#item :checkbox:not(:disabled)').prop('checked', this.checked);
});
http://jsfiddle.net/hRc4a/
$('#chkSelectAll').click(function () {
var checked_status = this.checked;
$('div#item input[type=checkbox]').each(function () {
if (!this.disabled)
this.checked = checked_status;
});
});
or without the each loop :
$('#chkSelectAll').on('click', function() {
var checked_status = this.checked;
$('div#item input[type=checkbox]').prop('checked', function(i, prop) {
return this.disabled ? prop : checked_status;
});
});
Or you may also use the :not selector as follows:
$('#chkSelectAll').click(function () {
var checked_status = this.checked;
$('div#item input[type=checkbox]:not(:disabled)').each(function () {
this.checked = checked_status;
});
});
$('input:checkbox:not(:disabled)').attr('checked', 'checked');
$('input:checkbox:not(:disabled)').removeAttr('checked');
refer below link for more details http://www.infinetsoft.com/Post/How-to-check-all-except-disabled/18#.V00SYfl97IU
I'd personally suggest this solution if you want select all rows except disabled one.
Just add this code in checkbox input(HTML)
onclick="$('input[name*=\'selected\']:not(:disabled)').prop('checked',this.checked);"
Use not() to exclude things with a disabled attribute.
$('#chkSelectAll').click(function () {
var checked_status = this.checked;
$('div#item input[type=checkbox]').not("[disabled]").each(function () {
this.checked = checked_status;
});
});
more concise
$('#chkSelectAll').click(function () {
var checked_status = this.checked;
$('div#item input[type=checkbox]').not(":disabled").prop("checked", checked_status);
});