.is () - use AND instead of the OR condition

At the moment, the result .is()will return true if ANY ( OR ) conditions true, how can I use it AND instead, i.e. return only trueif ALL conditions are met?

if ($('#search-form #valid_only').is(':checked, :enabled')) {

}
+3
source share
2 answers

This comma in your selector is equivalent to OR.

Use both conditions without a comma separating them inside is()

if ($('#search-form #valid_only').is(':checked:enabled') { // checked and enabled
    ...
}

Or, if you want to check :checked, :enabledand have a class name foo, you can do.foo:checked:enabled

+5
source

You can simply combine your selectors:

if ($('#search-form #valid-only').is(':checked:enabled')) {
}
+2
source

All Articles