Last active
May 21, 2025 11:08
-
-
Save black1277/a0e2fab20133c7232c674825ca3349e1 to your computer and use it in GitHub Desktop.
DOMContentLoaded
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener("DOMContentLoaded", ()=>{ | |
init() | |
}) | |
function init(){} | |
// альтернатива событию DOMContentLoaded | |
document.onreadystatechange = function () { | |
if (document.readyState == "interactive") { | |
init() | |
} | |
} | |
document.onreadystatechange = function () { | |
switch (document.readyState) { | |
case "loading": | |
// Страница все ещё загружается | |
break; | |
case "interactive": | |
// Страница уже загружена. Теперь мы можем получить доступ к DOM объектам. | |
var span = document.createElement("span"); | |
span.textContent = "A element."; | |
document.body.appendChild(span); | |
break; | |
case "complete": | |
// Страница загружена вместе с дополнительными ресурсами. | |
console.log( | |
"The first CSS rule is: " + document.styleSheets[0].cssRules[0].cssText, | |
); | |
break; | |
} | |
} | |
window.addEventListener("load", function (event) { | |
console.log("All resources finished loading!"); | |
}); | |
document.addEventListener("readystatechange", (event) => { | |
log.textContent = log.textContent + `readystate: ${document.readyState}\n`; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment