Let’s say I have huge tree view and one the branches is in variable called $branch and now I want to check does that branch contain none or more than one element with expand classes. In other words boolean should be returned as soon as one match is found.
Okay, I can do this with $branch.find('.expand').length > 0, but is there a better way that would stop on the first matching element and therefore would be faster?
I think using first() reduces existing set to length of one, so I would have use find() and then reduce?
Ps. As you noticed in the example I used find() because I want to go deeper than just children of the $branch
Standard CSS selectors like this use the native DOM method querySelectorAll(). I.e. they run in the browser’s native code and they’re fast. Unless you’ve got reason to think that doing the above is slow, I doubt you need to worry about it.