Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.onload equivalent after modifying the DOM?

When a page first loads we can use window.onload to make sure that all resources have loaded before we do something.

My question is, if we modify the DOM (e.g. inserting some html based on an ajax request), is there any event that will fire when the document is in the 'loaded' state again? (e.g. when the html inserted contains multiple images).

(Solution with jQuery would be fine).

like image 979
UpTheCreek Avatar asked Nov 03 '22 01:11

UpTheCreek


1 Answers

The short answer: NO.

The long answer: if you know what you are looking for you can use mutation observers (https://developer.mozilla.org/en-US/docs/DOM/MutationObserver). it is only support in new browser, and in some version of chrome it has memory leaks when used with closures.

BTW, document.ready doesn't tell you if all (or any..) of the resources were loaded. it only tell you well, that the dom is ready (that is the load function, which will only fire after all resources (well, any resources that isn't requested using a javascript) were downloaded).

like image 114
Nadav Ben-Gal Avatar answered Nov 12 '22 19:11

Nadav Ben-Gal