@manhnguyenv

Welcome to my blog!

Document Ready

January 2, 2019 12:20

Document Ready (edit)

https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded

https://codepen.io/LukeAskew/pen/LnJsE

https://ehkoo.com/bai-viet/co-the-ban-khong-can-jquery

<script>
//Way 1:
document.addEventListener("DOMContentLoaded", function(event) {
console.log("DOM fully loaded and parsed");
});

//Way 2:
function doSomething() { console.info("DOM loaded"); } if (document.readyState === "loading") { // Loading hasn't finished yet document.addEventListener("DOMContentLoaded", doSomething); } else { // 'DOMContentLoaded' has already fired doSomething(); }

//Way 3:
GLOBALS = {}; GLOBALS.myFunc = function (e) {
// ...
}
document.addEventListener('DOMContentLoaded', GLOBALS.myFunc, false);
</script>

Categories

Recent posts