Is bubbling available for image load events?

Use capturing event listener on some DOM node other than window (body or other parent of image elements of interest):

document.body.addEventListener(
    'load',
    function(event){
        var tgt = event.target;
        if( tgt.tagName == 'IMG'){
            tgt.style.display = 'inline';
        }
    },
    true // <-- useCapture
)

With this you don’t have to (re)attach event handlers while iterating through document.images.

And this will work for dynamically inserted images as well.

Same is true for image’s error loading events. MDN: addEventListener

Leave a Comment