0
Why won't it go invisible when you press "dog"?
5 Answers
+ 4
https://code.sololearn.com/WWqIvUhPwSpn/?ref=app
getElementsByClassName returns array and one semicolon was missing
+ 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
+ 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 "
+ 1
must press cat
0
Thanks both