DIVs with style.display none still showing up
on loading a page I have some javascript code which hides some layers
document.getElementById(layerName).style.display = "none";
Everything work开发者_Python百科s well, but in IE and in Opera these DIVs are showing up for the first few milliseconds while the page loads. After that, it's back to normal.
Is there a way around that?
Thanks!
If you run code when the page loads, it will not run until the page finishes loading.
Instead, you can put the code in a <script>
block below the elements, without handling onload
.
Or you just use CSS.
you could set display to false in you HTML code
Is there a way around that?
It's called CSS:
.layer {
display:'none';
}
This problem occurs because of the way the browser renders the page. CSS is first before Javascript. So always try to do things in CSS when possible.
place this script immediately below the div placed. you will almost clear the problem
精彩评论