I’ve tracked down a Javascript problem I’ve been having, the problem can be seen in this code, ran after page load:
var btns = document.getElementsByTagName('button');
console.log(btns);
divs = document.getElementsByTagName("div");
console.log(btns.length);
console.log(btns);
When this code works, (and doesn’t show blank array []), it shows the array of buttons, then 0, then array of buttons, in the console. How can this be returning the wrong value for length??
It looks like setting it as a DOMContentLoaded event fixed this.
seems to be the correct event to set the onload code.