In CSS, setting a visibility attribute to hidden for a class, then getElementsByClassName[i].style.visibility, will not recognize the class as hidden.
Only after the onChange executes for the second time does the css actually change. The first onChange call does not recognize the css is set to visibility: hidden
, and the else applies the "hidden" attribute.
To prove this, when else is replaced with else if, the visibility will never change, as it's not read as visible or hidden
However, if I use style.visibility != "hidden" and style.visibility != "visible"
the code will work properly.
Can anyone enlighten me as to why this happens, and how I can properly set attributes to be read by js?