Possible Duplicate:
javascript domready?
I want to check whether $(function(){ });
is "ready".
Return true if DOM is ready, false otherwise
From jQuery code
if ( jQuery.isReady ) { fn.call( document, jQuery ); }
You can use the explicit call
$(document).ready(function(){
// do this after dom is ready
});
Or use the shortcut
$(function(){
// do this after dom is ready
});
It's also useful to wrap your jQuery in an anonymous function when you're using other libraries; Also very common to use this when writing jQuery plugins.
(function($, window){
// use $ here freely if you think any other library might have overridden it outside.
$(function(){
// do this after dom is ready
});
})(jQuery, window);
Lastly, you can use jQuery.isReady
(bool)
if (jQuery.isReady) {
// do something
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With