document. onload | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 12

document. onload

Why the javascript code doesn't run on just loading of a document object.(...document.onload)..even if all the HTML,css elements,attributes,properties are loaded.Why we use windows.onload instead?

22nd May 2020, 7:12 AM
🧸A B H I S H E K🧸
🧸A B H I S H E K🧸 - avatar
1 Answer
+ 3
Heres what Lorenz Lo Sauer said: "The general idea is that window.onload fires when the document's window is ready for presentation and document.onload fires when the DOM tree (built from the markup code within the document) is completed." "Ideally, subscribing to DOM-tree events, allows offscreen-manipulations through Javascript, incurring almost no CPU load." "Contrarily, window.onload can take a while to fire, when multiple external resources have yet to be requested, parsed and loaded" Retrieved from: https://stackoverflow.com/questions/588040/window-onload-vs-document-onload
22nd May 2020, 7:35 AM
Nootnoot
Nootnoot - avatar