Reputation: 2698
I'm trying to write a simple jQuery slider, and I need to find the number of elements with a particular class. Is there a way to do this?
Upvotes: 2
Views: 78
Reputation: 14777
var $elements = $('.classname'); // cache the result of your query
var numberOfElements = $elements.length; // slightly faster than .size()
If you use the .length property you will skip a function call. The size() function merely returns this.length
.
Upvotes: 3