0
Please look at my code and tell me what's wrong there, I want hide/show content or div button
PLACE CONTENT THAT YOU DONâT WANT TO HIDE HERE <div id=âHIDDENâ style=âdisplay:noneâ> PLACE CONTENT THAT YOU WANT TO HIDE HERE </div> <button title=âshow/hideâ type=âbuttonâ onclick=âif (document.getElementById(âHIDDENâ) .style.display==ânoneâ) {document.getElementById(â HIDDEN â) .style.display=â}else {document.getElementById(â HIDDEN â) .style.display=ânoneâ}â>Show/hide-content</button>
3 RĂ©ponses
+ 4
Try to use the code as a function like that
https://code.sololearn.com/WV3vZcx4OBEr/?ref=app
+ 3
and the error in your code, here solution
<div id="HIDDEN" style="display:none;" >
CONTENT TO HIDE
</div>
<button title="show/hide" onclick="sh()"></button>
<script>
function sh() {
let elem = document.querySelector("#HIDDEN");
if(elem.style.display=="none"){
elem.style.display = "block" ;
} else {
elem.style.display = "none";
}
}
</script>
0
Thank you so much man, it was really helpful