Valip
Valip

Reputation: 4610

How can I simplify a jQuery condition?

I have an OR condition that checks if any of two checkboxes are checked, it works great but I am wondering if there are some other ways of implementing this to simplify code...

It would be great if this can be done with defining private class in a varibale. forum_private = $('.private').first().prop("checked") || $('.private').last().prop("checked")

I tried with forum_private = $('.private').filter(':checked') but this doesn't works.

Upvotes: 1

Views: 49

Answers (1)

Tushar
Tushar

Reputation: 87203

You can simplify the statement as

$('.private:first:checked, .private:last:checked').length >= 1

Upvotes: 1

Related Questions