I have a loop which generates <li>
with custom attribute filesize
, now I want to search all <li>
with this class and sum the value, but instead it returns two values next to each other and not summing the values.
https://jsfiddle.net/y6yLL0yv/1/
var myElements = jQuery(".fileRess");
var sumoffilessize = 0;
for (var i = 0; i < myElements.length; i++) {
var valueofthis = myElements.eq(i).attr("sizefile");
var valuetostr = valueofthis.toString();
var sumoffilessize = (valuetostr + sumoffilessize);
}
alert(sumoffilessize);
HTML:
<div id="fileInfo1">
<div style="clear:both;padding:5px;" class="fileRess" sizefile="206519" id="fileres_0">
<input size="1" type="file" class="file" name="attach[]" id="attacher" style="display:none" multiple="" value="undefined">206519 </div>
<div style="clear:both;padding:5px;" class="fileRess" sizefile="290284" id="fileres_1">
<input size="1" type="file" class="file" name="attach[]" id="attacher" style="display:none" multiple="" value="undefined">290284 </div>
</div>
<div id="result"></div>