get a total of jquery's .each()

Two options:

$('#accordion li').size(); // the jQuery way
$('#accordion li').length; // the Javascript way, which jQuery uses

Since jQuery calls length under the hood, it's faster to use that instead of the size() call.


$('#accordion li').length;

Well, I just saw this question, and you already accepted an answer, but I'm going to leave one anyway.

The point of the question seems to be concerned with incrementing a counter.

The fact is that jQuery's .each() method takes care of this for you. The first parameter for .each() is an incrementing counter, so you don't need to do it yourself.

$('#accordian li').each(function(index) {
       // index has the count of the current iteration
    console.log( index );
});

So as you can see, there is an elegant solution built in for you.