Skip to content

Instantly share code, notes, and snippets.

@evantbyrne
Last active January 30, 2018 17:37
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 evantbyrne/7290fcb8957f3bfc80259bfd969dde03 to your computer and use it in GitHub Desktop.
Save evantbyrne/7290fcb8957f3bfc80259bfd969dde03 to your computer and use it in GitHub Desktop.
DOM ready
// Example using the module.
import domready from "./domready.js";
domready(function() {
//...
});
// Runs `callback` once DOM has been loaded.
// Supported by IE9+ and modern browsers.
export default function(callback) {
if(document.readyState === "complete") {
callback();
} else {
document.addEventListener("DOMContentLoaded", callback);
}
}
// Example without using the module.
function ready() {
//...
}
if(document.readyState === "complete") {
ready();
} else {
document.addEventListener("DOMContentLoaded", ready);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment