Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: $(document).ready() too slow in IE

What would be the preferred way of hiding an element before the page is rendered? $(document).ready() works just fine for firefox, but sometimes (connection to the server seems to be a major issue in this) it lags a little behind in internet explorer; the element is shown, and hidden shortly after wards. That is: the page is rendered before code in $(document).ready() is executed.

Now I've been looking through previously asked questions on SO about similar issues, but these are reported to be solved in 1.3.1. I am however, using jQuery 1.3.2 and experiencing this behavior (in IE6, IE7 and IE8).

One possible option would be to hide it by default through css, but this would make showing it dependent of having javascript enabled. I'm not willing to do that just yet.

I have also tried to move my javascript just above the /body tag, which doesn't seem to help either.

like image 676
Daniel Sloof Avatar asked Apr 20 '09 23:04

Daniel Sloof


People also ask

How do I know if a jQuery document is ready?

A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside $ ( document ).ready () will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.

How to pass function to $ (document).ready () in jQuery?

Experienced developers sometimes use the shorthand $ () for $ ( document ).ready (). If you are writing code that people who aren't experienced with jQuery may see, it's best to use the long form. console.log ( "ready!" ); You can also pass a named function to $ ( document ).ready () instead of passing an anonymous function.

Should I use jQuery $ () or $ ()?

Experienced developers sometimes use the shorthand $() for $( document ).ready().If you are writing code that people who aren't experienced with jQuery may see, it's best to use the long form.


1 Answers

Wow, this is going to be a quick one...

This document shows exactly what I was looking for, I hope it'll help someone some day :)

like image 197
Daniel Sloof Avatar answered Oct 31 '22 04:10

Daniel Sloof