Reputation: 9037
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
Upvotes: 1
Views: 262
Reputation: 51807
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.
Upvotes: 1
Reputation: 5563
document.getElementById('tree').style.display='';
Include this in your check function
Upvotes: 2