Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
59
rated 0 times [  60] [ 1]  / answers: 1 / hits: 178596  / 12 Years ago, tue, march 13, 2012, 12:00:00

I have a main div in my page with a specific id. Now some input elements of the same class are present in this div. So how can I count the number of these elements of same class in this div using jQuery?


More From » jquery

 Answers
3

With jQuery you can use



$('#main-div .specific-class').length


otherwise in VanillaJS (from IE8 included) you may use



document.querySelectorAll('#main-div .specific-class').length;

[#86881] Monday, March 12, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
monetm

Total Points: 615
Total Questions: 103
Total Answers: 119

Location: Finland
Member since Fri, Oct 21, 2022
2 Years ago
;