I have the following code to display a div that was previously hidden:
document.getElementById('theDiv').style.display = 'block';
The problem is that when I execute this, the div loses all prior CSS formatting. Is there a way that I can have this same functionality while keeping my CSS formatting?
Setting
style.displaytoblockhas no effect on other CSS formatting. The only one exception I can think of is if the item was previouslydisplay:inline, then setting it todisplay:blockwould change the layout. But, all other CSS items will be unaffected.If this is not what you are observing, then you may not be telling us the whole story here and something else that you aren’t showing us with your code must be going on. If that’s the case, then please try to reduce your test case to a small example in jsFiddle so we can see the actual code that causes the problem.