I use this code to add values that has class name. Jsfiddle. I specifically want to add values of divs with class name box
and has css attribute display block
.
var test = document.getElementsByClassName("box");
var sum = 0;
for (i = 0; i < test.length; i++) {
sum += parseInt(test[i].textContent);
}
console.log(sum);