Pretty simple to do with loop but I’m wondering if there’s a way to see if every item in a collection matches a condition without a loop. For example:
if( $('.many-items-of-this-class').hasClass('some-other-class') ) { }
This returns true if any item in the collection returns true. Is there a way to do this sort of operation so it only returns true if all items are true?
You could cache the set, then run a filter against the set that tests for the other class, and compare the
.lengthproperties of both.Or shorter, but arguably more confusing, you could use a
.not()filter with.lengthand a!.