Nick Heiner Nick Heiner - 5 months ago 8
jQuery Question

jQuery: See how many elements a selector matched?

If I have a selector like

$.('.active');


How can I see how many items that matched?

Alternatively, is there an easy way to see if more than zero elements were matched?

Answer

call .length on the returned set.

Do not use .size because:

The .size() method is deprecated as of jQuery 1.8