$(document).bind( 'ready', fn ) fn never execs if called after dom ready fires.
http://benalman.com/
by Ben Alman
HTML
<b>Not a bug, per se.. but should be documented or fixed.</b>
<br>
<br>
$(document).bind( 'ready', fn ) fn never execs if called after dom ready fires.
<br>
<br>
<div id="log"></div>
JavaScript
$(function(){
log("1. $(fn)");
$(function(){
log("2. $(fn) -> $(fn)");
});
$(document).bind( 'ready', function(){
// Executes because it is bound before the last
// DOM ready handler has executed.
log("3. $(fn) -> $(document).bind( 'ready', fn )");
});
});
$(document).bind( 'ready', function(){
log("4. $(document).bind( 'ready', fn )");
$(function(){
log("5. $(document).bind( 'ready', fn ) -> $(fn)");
});
$(document).bind( 'ready', function(){
// Doesn't execute because it is bound while the
// last DOM ready handler is executing.
log("6. $(document).bind( 'ready', fn ) -> $(document).bind( 'ready', fn )");
});
setTimeout( foo, 100 );
});
function foo(){
log("7. setTimeout");
$(function(){
log("8. setTimeout -> $(fn)");
});
$(document).bind( 'ready', function(){
// Doesn't execute because it is bound after the
// last DOM ready handler has executed.
log("9. setTimeout -> $(document).bind( 'ready', fn )");
});
};
function log(txt){
$('#log').append(txt+'<br/>');
}