How does jQuery's "document ready" function work? -
how jquery checking if document loaded? how checking document load finished?
check out function bindready in source code.
they bind domcontentloaded event (or onreadystatechange on browsers). have fallback regular load event, in case domcontentloaded isn't supported or not fired other reasons. on browsers supporting it, use call:
document.addeventlistener( "domcontentloaded", domcontentloaded, false );
on ie <9:
document.attachevent( "onreadystatechange", domcontentloaded);
the second instance of domcontentloaded
in these calls own function - reference ready
function right above bindready
in source code. function check dom tree done checking document.body
. if doesn't exist yet, wait millisecond (using settimeout) , check again. when document.body exists, traverse list of callbacks you've set.
Comments
Post a Comment