Reputation:
I have JavaScript code that hides a tag when it is clicked:
document.getElementById("div").style.visibility="hidden";
Although when I do this, even though the div tag is hidden, there is still a space where the div tag is located. how do I collapse the whole div tag using JavaScript?
Upvotes: 3
Views: 28722
Reputation: 9469
Use
document.getElementById("divID").style.display = "none";
OR
document.getElementsByTagName("div").style.display = "none";
NOTE: document.getElementById()
only select the elements having id
attributes.
Upvotes: 0
Reputation: 11431
You should use:
document.getElementById("div").style.display = "none";
Just to mention that getElementById()
will be looking for a div
with the id of div
, I suggest you change this to something more obvious, an example would be:
<div id="container"><!--Content--></div>
Then your JavaScript could be:
document.getElementById("container").style.display = "none";
Check here to see what the difference is between display:none
and visibility:hidden
Upvotes: 7
Reputation: 643
Try this ..
document.getelementById("div_id").style.display = 'none';
Upvotes: 2