I’m using jquery’s .each() to iterate over a group of li’s. I need a total of all the li’s matched. Is the only way to create a count variable outside the .each() and increment this inside the .each()? It doesn’t seem very elegant.
var count;
$('#accordion li').each(function() {
++count;
});
Two options:
Since jQuery calls length under the hood, it’s faster to use that instead of the size() call.