Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
[JavaScript] document ready (plain method)
function document_ready(callback){
function completed(){
document.removeEventListener("DOMContentLoaded", completed, false);
self.removeEventListener("load", completed, false);
self.setTimeout(function(){ callback(); },10); //timeout helps to execute in a semi-async way.
if("loading" !== document.readyState){ //interactive or complete
else{ //loading
document.addEventListener("DOMContentLoaded", completed, false); //Use the handy event callback.
self.addEventListener("load", completed, false); //A fallback to window.onload, that will always work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.