Skip to content

Instantly share code, notes, and snippets.

@kadavre
Created June 18, 2017 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kadavre/28400b4bebc2253a57fea7eb1ac4f77c to your computer and use it in GitHub Desktop.
Save kadavre/28400b4bebc2253a57fea7eb1ac4f77c to your computer and use it in GitHub Desktop.
// with jQuery
$(document).ready(function(){ /* ... */ });
// shorter jQuery version
$(function(){ /* ... */ });
// without jQuery (doesn't work in older IEs)
document.addEventListener('DOMContentLoaded', function(){
// your code goes here
}, false);
// and here's the trick (works everywhere):
r(function(){
alert('DOM Ready!');
});
function r(f){/in/.test(document.readyState)?setTimeout('r('+f+')',9):f()}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment