corroded
corroded

Reputation: 21564

is there a jquery one liner code for toggling ENABLED checkboxes?

Is there a jquery method/whatever to toggle all checkboxes EXCEPT disabled ones? i have this code right now:

$('.select-all-categories').toggle(function() {
  $('#test-categories input[type="checkbox"]').attr("checked", false);
  return false;
}, function() { 
  $('#test-categories input[type="checkbox"]').attr("checked", true);
  return false;
});

and it works fine(selects/deselects all checkboxes). BUt some of the checkboxes are disabled and I would like it to NOT be affected by the toggle. Is there a way to do this WITHOUT doing a for each and looping through all and checking if they are disabled or not?

Upvotes: 1

Views: 347

Answers (1)

BoltClock
BoltClock

Reputation: 723688

Use :enabled to only select checkboxes that are enabled:

$('#test-categories input[type="checkbox"]:enabled')

By the way, you can replace [type="checkbox"] with :checkbox:

$('#test-categories input:checkbox:enabled')

Upvotes: 5

Related Questions