DOMContentLoaded
document.addEventListner('DOMContentLoaded',function(){
})
document.onload
document.onload(function(){
});
Is DOMContentLoaded and document.onload events are same
DOMContentLoaded
document.addEventListner('DOMContentLoaded',function(){
})
document.onload
document.onload(function(){
});
Is DOMContentLoaded and document.onload events are same
The syntaxe should be (as a comment pointed out) :
document.onload = function(){};
and I think it does only work when targeting an elemnt like so :
document.getElementById('image').onload = function(){};
It will assign the function to the onload handler.
Whereas
document.addEventListener('DOMContentLoaded', function(){})
Waits for the DOM to be ready before triggering, meaning that images, iframes, ect... could not be loaded.
Could be useful for someone
source : Difference between DOMContentLoaded and load events
DOMContentLoaded==window.onDomReady()
Load==window.onLoad()
A page can't be manipulated safely until the document is "ready."jQuery detects this state of readiness for you. Code included inside $( document ).ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute. Code included inside $( window ).load(function() { ... }) will run once the entire page (images or iframes), not just the DOM, is ready.
See: http://learn.jquery.com/using-jquery-core/document-ready/