function domReady(fn) {
if (document.readyState !== 'loading') {
fn();
} else {
document.addEventListener('DOMContentLoaded', fn, { once: true });
}
}
// Usage
domReady(() => {
console.log('DOM is ready');
document.querySelector('#app').textContent = 'Hello!';
});
Create a free account and build your private vault. Share publicly whenever you want.