Substitute function for jQuery .error () function

2

I need to know which function to use in place of the .error() function.

$('img').error(function() {
    $('img').attr('src','img/erro.gif');
});

jquery 3.2.1 does not have this function. How can I resolve this?

    
asked by anonymous 30.10.2017 / 21:12

1 answer

0

According to official documentation :

  

As of jQuery 1.8, the .error() method is deprecated. Use .on( "error", tratador) to attach event handlers to the error event.

That is, change your code to:

$('img').on("error", function() {
    $('img').attr('src','img/erro.gif');
});
    
30.10.2017 / 21:23