Detectar cuando DOM esta listo en JS puro
La forma cross-browser para comprobar si el documento se ha cargado en JavaScript puro utiliza readyState
.
if (document.readyState === 'complete') {
// The page is fully loaded
}
Como detectar cuando el document esta listo…
let stateCheck = setInterval(() => {
if (document.readyState === 'complete') {
clearInterval(stateCheck);
// document ready
}
}, 100);
o con onreadystatechange…
document.onreadystatechange = () => {
if (document.readyState === 'complete') {
// document ready
}
};
Use document.readyState === 'interactive'
para detectar cuando el DOM esta listo.
MEET THE NEW JSTIPS BOOK
You no longer need 10+ years of experience to get your dream job.
Use the 100 answers in this short book to boost your confidence and skills to ace the interviews at your favorite companies like Twitter, Google and Netflix.
GET THE BOOK NOW
MEET THE NEW JSTIPS BOOK
The book to ace the JavaScript Interview.
A short book with 100 answers designed to boost your knowledge and help you ace the technical interview within a few days.
GET THE BOOK NOW