Why won't it go invisible when you press "dog"? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
25th Jul 2019, 7:36 PM
coffeecup
coffeecup - avatar
5 Answers
+ 4
https://code.sololearn.com/WWqIvUhPwSpn/?ref=app getElementsByClassName returns array and one semicolon was missing
25th Jul 2019, 7:50 PM
nidhi
+ 3
Rather than setting up the function within the onclick attribute in the HTML, you can instead just set it within the function - HTML: <div class="but" onclick="dog()"> <button>dog</button> </div><br /> JS: function dog(){ document.getElementById('para').innerHTML = 'dog'; document.getElementsByClassName('but')[0].style.visibility='hidden'; } Additionally, you seem to have forgotten to specify which element of class "but" you wanted to set the visibility of, so adding in the [0] just fixes that error
25th Jul 2019, 7:48 PM
Faisal
Faisal - avatar
+ 1
Can anyone tell me why this works only for the first click. I mean when you click any button again it shows error that ".... is not a function "
25th Jul 2019, 8:00 PM
nidhi
+ 1
must press cat
25th Jul 2019, 10:31 PM
slick
slick - avatar
0
Thanks both
25th Jul 2019, 7:51 PM
coffeecup
coffeecup - avatar