Reputation:
Im triying of get all element by class name but i cannot get
when i try to get a one lement this command works
document.getElementsByClassName('div1')[5].value
but this command not works
var i=0;
for ( i < 6; i++) {
x = document.getElementsByClassName('div1')[i].value ;
}
var elementHtml = x;
i obtain this error
SyntaxError: missing ; after for-loop condition index.html:9:16 ReferenceError: downloadDiv is not defined
i get this error also
****TypeError: document.getElementsByClassName(...)[i] is undefined[Saber más]
please somebody help me
=============================================================
i put the response thankyou for your answers
var i = 0;
var x = 0;
for(var i = 0; i < document.getElementsByClassName('div1').length; i++){
x = x + document.getElementsByClassName('div1')[i].value;
}
var elementHtml = x;
Upvotes: 0
Views: 70
Reputation: 4051
You have made a mistake in your for loop in relation to your question;
for (var i=0; i < 6; i++) {
x = document.getElementsByClassName('div1')[i].value;
}
var elementHtml = x;
Upvotes: 1