Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Count unique occurrences of class

Tags:

jquery

I have a number of elements on my page that belong to classes with unique identifiers, based on my backend programming. Such that I may have the following:

<element class="element-1"></element>
<element class="element-1"></element>
<element class="element-2"></element>
<element class="element-2"></element>
<element class="element-3"></element>
<element class="element-3"></element>

Is there a way I can count the unique occurrences of these classnames with jQuery, so that whatever function would do that would return 3?

like image 937
neezer Avatar asked Sep 30 '09 19:09

neezer


1 Answers

the answer is much simpler: $("element.element-1").length;

like image 200
ManoCarayannis Avatar answered Nov 16 '22 02:11

ManoCarayannis