1

I am trying to get error on img load through on, but it doesn't work

$(document).on("error","#someid img",
               function(){
                  console.log("Image load error through On");
              });

but the similar works with 'bind'

$("#someid img").bind("error", function() {
                         console.log("Image load error through bind");
                      });
Mudit Tuli
  • 3,159
  • 3
  • 18
  • 26

2 Answers2

2

The issue is that the error event doesn't bubble, so you can't use event delegation to capture it at the document level.

The only way to capture it will be to bind directly to the element.


You can determine this by using the .bubbles property on the event object in your .bind() handler.

$("#someid img").bind("error", function(event) {
    console.log(event.bubbles); // false
});
user2736012
  • 3,503
  • 13
  • 13
0
 $("#your_id").error(function () {
     alert("your text")
 })
  1. .on() replaces .bind(), .live() and .delegate() after jquery1.7.
  2. .on() manages event delegation, bind doesn't.
  3. What is event.delegation?
Community
  • 1
  • 1
HIRA THAKUR
  • 15,044
  • 14
  • 47
  • 82