Reputation: 12695
I need some help, I have some checkboxes like that
<input class="some-class" type="checkbox" has-format="0">
or
<input class="some-class" type="checkbox" has-format="1">
Is it possible, to check, if all of that checked checkboxes has the has-format
value = 1 or 0 ? I mean, e.g. if I want to check = 1 then if any of the checked checkboxes has that value 0 then I'll get false
Upvotes: 0
Views: 61
Reputation: 349042
You can combine the :checked
selector with the attribute selector. The following variable is only true
if all of the specified conditions are met.
var checked_and_format1 = !$('.some-class:checked[has-format!=1]').length;
// Selects:
// .some-class
// which is checked
// and has a `has-format` property which is not 1.
// If the collection's size is zero, then we can assume that the whole
// .some-class:checked collection is valid.
If you're sure that there's no other value besides 1 and 0, you can replace [has-format!=1]
with [has-format=0]
.
Upvotes: 2
Reputation: 150263
var isValid = $('.some-class:checked[has-format="0"]').length == 0;
Upvotes: 1