silkfire
silkfire

Reputation: 25965

.is() - use AND instead of OR condition

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

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

}

Upvotes: 3

Views: 81

Answers (2)

techfoobar
techfoobar

Reputation: 66663

That comma in your selector is equivalent to an 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 for :checked, :enabled and having a class name foo, you can do .foo:checked:enabled

Upvotes: 5

yoavmatchulsky
yoavmatchulsky

Reputation: 2960

You can just combine your selectors:

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

Upvotes: 2

Related Questions