Methods to hide and reveal HTML elements, which is better?
Moderator: General Moderators
Methods to hide and reveal HTML elements, which is better?
I have sometimes used Javascript to assign an object's .innerHTML to either a null string or something else, and I have sometimes used the object's .style.display to be either "hidden" or "block". Does anyone have guidelines as to why one should be used in various circumstances?
I'd use the style to hide/display. And I'd use javascript to hide the element, that way users without javascript enabled will still be able to view all of the content.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Use CSS for sure - it's way faster and more reliable, IIRC.
display: none|block|inline; will remove the element entirely from the layout (block|inline depends on the element type, i.e. Block Elements like Divs or inline elements like Spans)
visibility: hidden|visible will make the element in/visible, but it remains "laid out" - which essentially means there will be a hole where the element used to be.
display: none|block|inline; will remove the element entirely from the layout (block|inline depends on the element type, i.e. Block Elements like Divs or inline elements like Spans)
visibility: hidden|visible will make the element in/visible, but it remains "laid out" - which essentially means there will be a hole where the element used to be.