How to select unchecked but not vague states

My checkbox list consists of checked, unchecked, and indefinite (third) state. For those who are wondering, I use jQuery to set an undefined state for some checkboxes. In the end, I would like to find and highlight all flags with an uncontrolled state, but not an undefined state using jQuery.

Here are my flags

<div id="list">
    <input id="item-1" type="checkbox">
    <input id="item-2" type="checkbox">
    <input id="item-3" type="checkbox"> 
    <!-- and so on -->
</div>

I can get verified using

var checkedItems = $("#list").find("input:checkbox:checked");

I can also get all the uncontrolled following

var uncheckedItems = $("#list").find("input:checkbox:not(:checked)");

However, it uncheckedItemswill return to me elements that also have an undefined state.

I also tried the following, but got unsupported pseudo: indeterminate(…)

var uncheckedItems = $("#list").find("input:checkbox:not(:checked):not(:indeterminate)");

So, how do I select only unverified items without selecting undefined?

Thanks in advance.

+4
2

$("[type=checkbox]:not(:checked)")
  .filter(function () { return !this.indeterminate; });

. jsfiddle

+3

, , , . , Victory, :

$("[type=checkbox]:not(:checked):not(:indeterminate)")

JSFiddle

0

Source: https://habr.com/ru/post/1661256/


All Articles