jQuery counting elements by class – what is the best way to implement this?

What I’m trying to do is to count all of the elements in the current page with the same class and then I’m going to use it to be added onto a name for an input form. Basically I’m allowing users to click on a <span> and then by doing so add another one for more of the same type of items. But I can’t think of a way to count all of these simply with jQuery/JavaScript.

I was going to then name the item as something like name="whatever(total+1)", if anyone has a simple way to do this I’d be extremely grateful as JavaScript isn’t exactly my native tongue.

6 Answers
6

Leave a Comment