Skip to content

Instantly share code, notes, and snippets.

@htmlr
Created September 23, 2014 00:19
Show Gist options
  • Select an option

  • Save htmlr/7be4ad6cf13ef190b63c to your computer and use it in GitHub Desktop.

Select an option

Save htmlr/7be4ad6cf13ef190b63c to your computer and use it in GitHub Desktop.
Detecting DOM ready in jQuery
// If the DOM is already ready
if ( jQuery.isReady ) {
// Execute the function immediately
fn.call( document, jQuery );
} // ...
function myClickHandler(event) {
// do stuff
$(document).ready(function() {
// Do this immediately if DOM is loaded, or once it's loaded otherwise.
}
}
$(document).ready(function() {
window.domIsReady = true;
}
if (window.domIsReady) {
// do stuff
}
$(document).ready(function() {
// Handler for .ready() called.
});
$(document).ready(function() {
alert ("document is ready!");
});
jQuery(document).ready(function(){
alert("howdy");
});
<script type="text/javascript">
if (typeof jQuery == 'undefined')
{
alert('not loaded');
}
</script>
<script type="text/javascript">
if(!this.$)
{
alert('not loaded');
}
</script>
$(document).ready(function(){
alert('document ready here')
});
$(window).load(function(){
alert("All content has been downloaded to the web browser")
});
function doStuff() {
alert("The DOM and everything inside have loaded");
}
window.onload = doStuff;
$(document).ready(handler);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment