+ 1
Can someone help?
I'm trying to make hide and show buttons that I can click to hide and show the text. I've completed the hide button, but I need help with show. I want show to reset the output so it shows the text again. Is there code for this? If so, I would love to know it. https://code.sololearn.com/WNqR9cHEhJV4/?ref=app
3 odpowiedzi
+ 4
Or like this:
function hide() {
var header = document.getElementById("header");
header.style.display = "none";
}
function show() {
var header = document.getElementById("header");
header.style.display = "block";
}
+ 1
You could make header variable global, for example:
var header;
function hide() {
var body = document.getElementById("body");
header = document.getElementById("header");
body.removeChild(header);
}
function show() {
var body = document.getElementById("body");
if(body.firstChild)
body.insertBefore(header,body.firstChild);
else body.appendChild(header);
}
+ 1
Thank you guys