RSS Feed

‘jQuery’ Category

  1. Window load vs document ready

    March 29, 2012 by Dave

    I see this issue all the time and perhaps even more worryingly I see the use of setTimeout() in places to defer listeners.

    If you don’t need to wait for images/scripts to load use:

    (function ($) {
            $(document).ready(function () {
                    //Code here
            });
    })(jQuery);

    If you need to wait for media to load, use this:

    (function ($) {
            $(window).load(function () {
                    //Code here
            });
    })(jQuery);

    Simple as that!