1

I need to display on a webpage a div when a user clicks on a button. Does someone know how to do it ?

My code so far :

<body onload ="init()">
      <input type="button" value="Display the div tree" onclick="check();" />

      <script ="text/javascript">

      function check() {
      // I'd like to display on the page the div tree
      }

     </script>

      <div id = "tree" style="display:none"> // I don't want to display it unless the user clicks on the button "Display the div tree"
      </div>      

</body>

thanks,

Bruno

1
  • 3
    <script ="text/javascript"> => <script type="text/javascript"> Commented Apr 15, 2011 at 9:44

2 Answers 2

2
document.getElementById('tree').style.display='';

Include this in your check function

Sign up to request clarification or add additional context in comments.

1 Comment

@Bruno -just try placing your script on the top of your page surrounded by <head>
1

i'm not sure if i understood the question, this seems a bit too easy:

function check() {
  document.getElementById('tree').style.display=''; // or display='block';
}

EDIT :
the reason this dooesn't work for you is an error in your code. please change this line:

<script ="text/javascript">

to

<script type="text/javascript">

and everything wiill be fine. also, you should place the script in the head of your document, but thats not absolutely neccessary.

1 Comment

do you have a content in between your div that will tell you that it's displayed instead of just being <div id="tree" style="display:none"></div>?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.