Reputation: 685
i was working on some requirements of my project and one of the requirement was to hide/unhide a Div on client side(Project is in .net technology and div's visibility will be set on client side using JS)
Code Snippet:
var block = document.getElementById('Your_Div_Id');
block.style.display = "none"; //some where it works to hide
block.style.visibility = "hidden"; //some where it works to hide
my question is why?
This is just hit and trial. first one was not working in one place so I used second one.I could not got to know why...
Upvotes: 0
Views: 142
Reputation: 194
In case you dont want to use jQuery, Make sure your Id of element is unique and is set properly in javascript code
you may also try writing the code in one line as below :
document.getElementById("element-id").style.display="none";
Upvotes: 2
Reputation: 696
Remember that display: none and visibility: hidden are different. The first one "delete" the node from the DOM, and the other nodes can take it place. The second one just hide hide, but the node preserves it position and sizes.
Tip: Try to use jQuery
$("#foo").hide();
Upvotes: 1