-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,248
  • 6
  • 28
  • 42
  • 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

6

Had you googled it.

var arr = document.getElementsByClassName("classname")

arr.length
Sparkup
  • 3,686
  • 2
  • 36
  • 50
Shreedhar
  • 5,502
  • 3
  • 22
  • 27