I have multiple div elements with same id=’mydiv’.I want to calculate these divs and Iam using the code
document.getElementById('mydiv').length
But it is not working
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It won’t work as
getElementByIdwill always return an element with the specified ID and null if the specified ID doesn’t existFrom ECMA
What you can do is to assign each div with class
And iterate over:
If your clients support
document.getElementsByClassName(), it’s even more concise: