This is because A
is not an Array
. getElementByClassName
returns an HTMLCollection
which is live-updated due to changes in the document.
The easiest way to convert an array-like object into an array would be to do this:
var A = ...
// With ES5 code
var A_array = Array.prototype.slice.call(A);
// With ES6 code
var A_array = Array.from(A);
Or you can get NodeList
instead via querySelectorAll
, which won't live-update.
var A = document.querySelectorAll('.someclass');