0

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

2 Answers 2

2

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].

Sign up to request clarification or add additional context in comments.

Comments

1
var isValid = $('.some-class:checked[has-format="0"]').length == 0;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.