Here is some code that I created:
function get_coordinates(container) {
var x;
var y;
var divs = container.getElementsByTagName('div');
Array.from(divs).forEach(div => {
y += div.offsetTop+" ";
x += div.offsetLeft + " ";
});
const a = x + ";" + y;
console.log(divs);
return x+";"+y;
}
Check out the output in the console:
HTMLCollection(10) [div#selector_1.selector, div#selector_2.selector, div#selector_3.selector, div#selector_4.selector, div#selector_5.selector, div#selector_6.selector, div#selector_7.selector, div#selector_8.selector, div#selector_9.selector, div#selector_10.selector, selector_1: div#selector_1.selector, selector_2: div#selector_2.selector, selector_3: div#selector_3.selector, selector_4: div#selector_4.selector, selector_5: div#selector_5.selector, …]
Now, take a look at the return value:
undefined0 0 0 0 0 0 0 0 0 0 ;undefined0 0 0 0 0 0 0 0 0 0
I'm puzzled as to why I'm getting undefined at the beginning of both strings.