-1

Possible Duplicate:
How to Get Element By Class in JavaScript?

I have a div tag with a class name on it. I want to get that div tag using the class name and count the number of elements in them. I am not in a position to filter using ID. How do i achieve this?

Community
  • 1
  • 1
Kaushik Balasubramanain
  • 1,218
  • 6
  • 28
  • 38
  • 1
    A very cursory search would bring up lots of stuff on this. What have you tried? – Mitya Aug 14 '12 at 10:23
  • the duplicate marker is wrong btw. the asker didnt want to "select" the elements but he wanted to count them. – My1 Oct 13 '16 at 21:07

1 Answers1

4

Had you googled it.

var arr = document.getElementsByClassName("classname")

arr.length
Sparkup
  • 3,601
  • 2
  • 33
  • 49
Shreedhar
  • 5,292
  • 3
  • 20
  • 27