'How to bind load event for img
I know $('img').load(function(){}) can work. However, I want the img dom those haven't been created at first can also trigger the event. I wonder why the below doesn't work.
$(window.document).on('load', 'img', function(){
console.log('load', this);
})
Solution 1:[1]
jQuery doesn't support capture. So I had to use js's addEventListener.
document.body.addEventListener(
'load',
function(event){
var tgt = event.target;
if( tgt.tagName == 'IMG'){
console.log('load', tgt.src);
}
},
true
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | chengjiang |
