I have written a script to get the top distance of the body to a div, I have 4 divs.
I'd like to set a time out and get each height every 5 seconds.
<div class="printOutputs" id="print1"></div>
<div class="printOutputs" id="print2"></div>
<div class="printOutputs" id="print3"></div>
<div class="printOutputs" id="print4"></div>
I get the ids
var ids = Array.prototype.slice.call(document.querySelectorAll('.printOutputs')).map(function (element) {
return element.id;
});
Created a for loop - can't seem to get each height every 5 seconds just returns 0s
for (var i=0;i<= ids.length;i++) {
var limit = ids.length;
var el = document.getElementById(ids[i]);
(function(x) {
setTimeout(function(){
console.log(getTopPos(el));
if(x === limit){
console.log('It was the last one');
}
}, 1000 + (3000 * x));
})(i);
}
Working example here: