How can someone make a “Hide / Show” button in Javascript?
I’m in a Web design class and here’s a scenario I’m stuck on:
“Help me to code a HTML5 test that has the answers hidden on the page. There should be a button that will show the answer, but you are not allowed to use jQuery or var in your code.”
Sounds like one of those “Show spoiler” buttons, but I don’t know how to make those! HELP!
- Category: JQuery Questions
M. L.
Posted 10 months ago
Put the text you want to hide in a with an id.
This is the text I want to hide
To hide it, use JavaScript like this:
var a = document.getElementById(“answer”);
a.style.display=”none”;
To show it again, use JavaScript like this:
var a = document.getElementById(“answer”);
a.style.display=”";
If you want it initially hidden, do this:
This is the text I want to hide
(UPDATED: to break the long lines apart)
Other Questions
I’m in a Web design class and here’s a scenario I’m stuck on:
“Help me to code a HTML5 test that has the answers hidden on the page. There should be a button that will show the answer, but you are not allowed to use jQuery or var in your code.”
Sounds like one of those “Show spoiler” buttons, but I don’t know how to make those! HELP!
M. L.
Posted 10 months ago
Put the text you want to hide in a with an id.
This is the text I want to hide
To hide it, use JavaScript like this:
var a = document.getElementById(“answer”);
a.style.display=”none”;
To show it again, use JavaScript like this:
var a = document.getElementById(“answer”);
a.style.display=”";
If you want it initially hidden, do this:
This is the text I want to hide
(UPDATED: to break the long lines apart)
Other Questions
Login
Search
Recent Comments
- dgdg_dasdad on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- Anas Imtiaz on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- David D on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- Wolfman on How does JQUERY DIFFER FROM JAVASCRIPT ? WHAT IS ITJQUERY ?
- TnT on Having a Jquery PHP problem?


Seanguy
Posted 10 months ago
Have all of the answers defined on a page within DIV’s and then perform a CSS “display:Inline” or “display:none” change conditional with JavaScript using ID of the DIV.