Reputation: 54113
I have this:
$('.project-header').html('Projects (' + numProjects + ')');
$('.task-header').html('Tasks (' + numTasks + ')');
$('.case-header').html('Cases (' + numCases + ')');
Where numProjects should be for example:
$('.project-header').numElementsWith('.external-element');
Is there some way to get the number of elements matching the class like this?
Thanks
Upvotes: 1
Views: 78
Reputation: 5917
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
$("ul").children().length // 3
Upvotes: 0
Reputation: 207511
Use length!
var count = $('.project-header').find('.external-element').length;
Upvotes: 4