window.ready javascript example
Example 1: document ready without jquery
document.addEventListener("DOMContentLoaded", function(event) {
});
Example 2: javascript document load
window.addEventListener("load", function(event) {
console.log("Tutte le risorse hanno terminato il caricamento!");
});
Example 3: how to trigger events when the document loads in js
document.addEventListener("DOMContentLoaded", ready);
function ready() {
alert('DOM is ready');
alert(`Image size: ${img.offsetWidth}x${img.offsetHeight}`);
}
Example 4: js dom ready function
<!doctype html>
<html>
<head>
</head>
<body>
Your HTML here
<script>
(function() {
})();
</script>
</body>
</html>