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>

20th Feb 2019, 3:28 PM
Ajay Prasad
3 odpowiedzi
+ 4
Try to use the code as a function like that https://code.sololearn.com/WV3vZcx4OBEr/?ref=app
20th Feb 2019, 3:55 PM
InvBoy [ :: FEDE :: ]
InvBoy [ :: FEDE :: ] - avatar
+ 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>
20th Feb 2019, 4:01 PM
InvBoy [ :: FEDE :: ]
InvBoy [ :: FEDE :: ] - avatar
0
Thank you so much man, it was really helpful
20th Feb 2019, 4:06 PM
Ajay Prasad