I’m for years using something like this in my HTML for elements which should be hidden:
<div style="display: none"></div>
It’s ok, but I can’t stand in-line styles anymore.
-
Hiding elements programatically in JavaScript
window.onloadevent is too late — it will flash on the screen. -
I can create CSS class ‘hidden’, but with browser’s aggressive loading strategies (like in Opera) the block may appear for a second (before CSS is loaded).
Is there any better way?
As far as I know the
class="hidden"method is the best and most commonly used. I suggest you useclass="hidden".I don’t use Opera, but if any browser loaded the page before applying styles then a lot would look wrong, not just your hidden elements. I don’t know of any browser doing this.