Having trouble changing the CSS display property to "none" using JavaScript.
Check out my code:
<div class="mydiv" onClick="clickDiv1()">hello</div>
<div class="mydiv" onClick="clickDiv2()">hi</div>
<div class="mydiv" onClick="clickDiv3()">goodbye</div>
And here's my script:
function clickDiv1() {
alert('You clicked the first div!');
document.getElementByClassName('mydiv').style.display="none";
}
function clickDiv2() {
alert('You clicked the second div!');
document.getElementByClassName('mydiv').style.display="none";
}
function clickDiv3() {
alert('You clicked the third div!');
document.getElementByClassName('mydiv').style.display="none";
}
I want each div to show a different alert text when clicked, but all divs become invisible when any of them is clicked on.
The alerts work, but the style doesn't change as expected when I click on a div. Any ideas why it's not working?
Please assist me with this issue! Thank you!