+ 3
Why getElementsByClassName doesnt work?
wanna use innerHTML at button2 https://code.sololearn.com/W6MfGH0xPpuF/?ref=app https://code.sololearn.com/W6MfGH0xPpuF/?ref=app
2 ответов
+ 8
Add [0] after document.getElementsByClassName("bUt")
do like this:-
var z = document.getElementsByClassName("bUt")[0];
This is because when you use the 'getElementsByClassName' it returns an array..So we have to get the element by using the index, here it is the first element so we say [0].. Remember index starts from 0 not 1..
Alternative way, as z is the collection of array so we can also do this :-
z[0].innerHTML
But if you want a separate variable for the button use the first way
+ 4
Change z.innerHTML to z[0].innerHTML