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 ответов
+ 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