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
...
});
Previous
Distinguish between left and right mouse clicks
Next
Get css styles of an element