you are redefining arrow
in function scope, which is overshadowing global definition.
var arrow = 0;//global
var arrow = document.getElementsByClassName("active");// overshadowing assignment
Even if you fix is removing var
, hence -
arrow = document.getElementsByClassName("active");// var removed
When you use document.getElementByClassName
, you get an HTMLCollection
, not that element even if there is one match. Matching array using ==
does not behave in the way you want.
To fix that use -
if(arrow[0] == toparrow[0])//assuming you have only one element with class 'active' and 'toparrow' in dom