Why can't the original className? be changed by getElementsByClassName?





</body>
</html>

Why doesn"t this work?
to change class= "close" to id= "close"; through var gg=document.getElementById ("close"); to be effective?

Mar.31,2021

clipboard.png
this method returns a class array object, not a single element.
you can try
gg [0] .className = 'show'


getElementsByClassName () method returns a collection of elements of all the specified class names, and notice that the result is a NodeList object.
on this page like you, there is only one class of the same name that can be achieved through gg [0]. ClassName = "show"; to achieve the effect


getElementsByClassName () method returns an array, you save the variable without selecting the subscript, so it will not be executed.
and it is more reliable to use the ele.setAttribute () method to modify the dom property.

Menu