/html-dom /Basic
GitHub 4932★

Execute code when the document is ready

const ready = function (cb) {
// Check if the `document` is loaded completely
document.readyState === "loading"
? document.addEventListener("DOMContentLoaded", function (e) {
cb();
})
: cb();
};

// Usage
ready(function() {
// Do something when the document is ready
...
});
Follow me on and to get more useful contents.