Mike
Mike

Reputation: 853

PHP: count elements with same class

I am creating and filling an HTML table using PHP. During this each TR gets a certain class.

Is there a way I can count how many elements have this class so that I can echo the number somewhere on the page on page load ? (Other TRs would have different or no classes.)

Example TR:

<tr class="myClass"></tr>

Many thanks in advance, Mike.

Upvotes: 0

Views: 1292

Answers (2)

gatfil
gatfil

Reputation: 45

You use jQuery (enter link description here)

var n = $( "myClass" ).length;

Upvotes: 0

Noman Ghani
Noman Ghani

Reputation: 468

With Jquery:

$('.myClass').length

Upvotes: 1

Related Questions