Skip to content
Advertisement

Count the number of

Is it possible using jQuery to count the number of div elements?

I have this code:

<div id = "center">
  <div class ="name">text text</div>
  <div class ="name">text text text ... </div>
  <div class ="name">text ...</div>
</div>

And get number: 3

Advertisement

Answer

$("#center div").length will give you the count.

Advertisement