Is it possible to listen for a specific DOM element to be loaded? I have a window.onload
event that is called when the whole page loads, but I'm looking for a way for it to be called for each DOM element that gets loaded. (Does onload
not bubble up?)
Example:
function init() {
alert(this.id); // Should be in context of DOM element that bubbled up when loaded
}
window.onload = init;
<div id="one">One</div>
<div id="two">One</div>
<div id="three">One</div>
I want this code to alert one, two, three.
onload
events don't bubble like this, you have 2 options here:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With