It's been well answered that you have to define the div to be "hidden" on the CSS. Just an aditional explanation on why you have to do that.
It has to do with how is css rendered. As pointed out in another post here on SO:
Reference: How is CSS applied by the browser, and are repaints affected by it?
The browser reads the HTML tags as a stream, and applies what rules it can to the elements it has seen so far.
So, it means that css styles are applied as soon as the browser knows that the element exists. So your display: none
statement will be rendered instantly, and you won't even be able to see the div before it.
Js, on the other hand, works differently. While it can perform some actions before the page is loaded, its interactions with elements, such as a div
, must wait for the page render to be complete. That is why you have to define:
$( document ).ready(function() {
It tells the browser to render the document first, and then, when it is ready
, it can perform the javascript functions... So, that is why you can see the div for a small moment, and then JS hides it.
So yes, in order to hide it from the start, you have to go with CSS:
.errors, .errors1 {
display: none;
}