@manhnguyenv

Welcome to my blog!

jQuery Document Ready

June 29, 2019 09:43

jQuery Document Ready (edit)

https://www.sitepoint.com/jquery-document-ready-plain-javascript/

All browsers

window.addEventListener('DOMContentLoaded', (event) => {
    console.log('DOM fully loaded and parsed');
});

document.addEventListener('DOMContentLoaded', function(event) {
// Handler the event occurred
});

document.addEventListener("DOMContentLoaded", function() {
// Handler when the DOM is fully loaded
});

$(document).ready(function() { // Handler for .ready() called. });

$(window).on("load", function() { // Handler when all assets (including images) are loaded });

$(function() {
// Handler when all assets (including images) are loaded
});

Older versions of Internet Explorer

document.attachEvent("onreadystatechange", function() {
// check if the DOM is fully loaded
if(document.readyState === "complete") {
// remove the listener, to make sure it isn't fired in future
document.detachEvent("onreadystatechange", arguments.callee);
// The actual handler...
}
});

Categories

Recent posts