0

In Jquery there's $(window).load() which happens after $(document).ready(), when the page has fully loaded. From what I understand $(document).ready() happens even before the page fully loaded. In plain javascript there's window.onload which corresponds to $(window).load() Jquery. What javascript event corresponds to $(document).ready()?

boruchsiper
  • 1,846
  • 8
  • 27
  • 46
  • 1
    possible duplicate of [$(document).ready equivalent without jQuery](http://stackoverflow.com/questions/799981/document-ready-equivalent-without-jquery) – Rory McCrossan Feb 17 '12 at 08:17
  • See http://stackoverflow.com/questions/1283445/is-there-a-native-javascript-implementation-of-jquerys-document-ready – Crinsane Feb 17 '12 at 08:18
  • also http://stackoverflow.com/questions/1206937/javascript-domready – naveen Feb 17 '12 at 08:20
  • and this is how jquery bindReady http://james.padolsey.com/jquery/#v=1.6.2&fn=jQuery.bindReady – naveen Feb 17 '12 at 08:21

3 Answers3

1
 $(document).ready() 

this corresponds to window.onload(), .ready() executes after the HTML DOM is loaded in the browser window

.load() in jQuery can be used to load an random URL on the already open window context.. like an ajax call.

anix
  • 347
  • 4
  • 13
0

Have a read here, https://developer.mozilla.org/en/DOM/DOM_event_reference/DOMContentLoaded

Alex
  • 2,002
  • 1
  • 13
  • 16
0

The answer is here:

bindReady: function() {
    if ( readyList ) {
        return;
    }

    readyList = jQuery.Callbacks( "once memory" );

    // Catch cases where $(document).ready() is called after the
    // browser event has already occurred.
    if ( document.readyState === "complete" ) {
        // Handle it asynchronously to allow scripts the opportunity to delay ready
        return setTimeout( jQuery.ready, 1 );
    }

    // Mozilla, Opera and webkit nightlies currently support this event
    if ( document.addEventListener ) {
        // Use the handy event callback
        document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );

        // A fallback to window.onload, that will always work
        window.addEventListener( "load", jQuery.ready, false );

    // If IE event model is used
    } else if ( document.attachEvent ) {
        // ensure firing before onload,
        // maybe late but safe also for iframes
        document.attachEvent( "onreadystatechange", DOMContentLoaded );

        // A fallback to window.onload, that will always work
        window.attachEvent( "onload", jQuery.ready );

        // If IE and not a frame
        // continually check to see if the document is ready
        var toplevel = false;

        try {
            toplevel = window.frameElement == null;
        } catch(e) {}

        if ( document.documentElement.doScroll && toplevel ) {
            doScrollCheck();
        }
    }
},

from jQuery source code

core1024
  • 1,902
  • 15
  • 22