• Recent Questions
  • Popular Questions

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!

    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.

      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)

        David
        Posted 10 months ago

        Like this: http://jsfiddle.net/tQXzf/

      Answer this Question :

      You must be logged in to post an answer. Signup Here, it takes 5 seconds :)

      Other Questions