Last active
January 9, 2019 09:28
-
-
Save danielt69/6c49fade54359be530a927ab02087e9d to your computer and use it in GitHub Desktop.
document.ready my version of JQuery's $(document).ready()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.ready = function(f){ | |
f = f || function(){}; | |
if (document.readyState == "interactive" || "complete") { | |
f(); | |
} else { | |
document.addEventListener("DOMContentLoaded", function(e) { | |
f(); | |
}); | |
} | |
} | |
/////////////////////// | |
//Ready | |
function ready(fn){var d=document;(d.readyState=='loading')?d.addEventListener('DOMContentLoaded',fn):fn();} | |
//Use like | |
ready(function(){ | |
//some code | |
}); | |
//For self invoking code | |
(function(fn){var d=document;(d.readyState=='loading')?d.addEventListener('DOMContentLoaded',fn):fn();})(function(){ | |
//Some Code here | |
//DOM is avaliable | |
//var h1s = document.querySelector("h1"); | |
}); | |
//Support: IE9+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment