In some JavaScript, I hide an element by doing this:
element.style.display = 'none';
When I want to display it again, I could do that same thing and set it to block
. However, I won’t know what it was before I changed it. It could have been inline-block
for all I know.
This means that I can’t really use this method, unless I wanted to store the prior value first. (Something I could conceivably do…)
I thought about moving to some hidden area (like a template
tag or something), but then I’d have to have some way of remembering exactly where it came from.
Is there another way to remove an element from the layout (so display
, not visibility
), without changing the display
style property, so that I don’t have to worry about getting it back to what it was?
2
Answers
You can store the state it was before setting it to
none
.Set an empty string to the display property