Is it going to run on client side?
If so, you can use jQuery to do this very easily.
$('div').length
will give you the count of divs.
To see it in action right here, you can:
1. Pres F12 (get the web browser console open in most browsers)
2. copy the line of code above.
3. paste into the browser console
4. press <enter>
I get 195 for this (CP) page.
Here's a snapshot of what I see in the console output:
https://i.stack.imgur.com/poGrV.png[
^]
Pure JavaScript
If you don't want to use jQuery or it's not available you can use pure JS code:
document.getElementsByTagName('div').length
Again, you can test that here in the console window of your browser.