TypeError: $ (...) .error is not a function

2

I have an error code in the latest version of jQuery v3.1.1 In version 1 there is no error. Here is the code:

//IMAGE ERROR
$('img').error(function () {
    var s, w, h;
    s = $(this).attr('src');
    w = s.split('&')[1].replace('w=', '');
    h = s.split('&')[2].replace('h=', '');

    $(this).attr('src', '../tim.php?src=admin/_img/no_image.jpg&w=' + w + "&h=" + h);
});

Error documentation: documentation here

    
asked by anonymous 14.12.2016 / 12:09

2 answers

9

Look at the jQuery documentation, which says:

  

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

That is, the way you are calling is obsolete. More information on the jQuery site.

    
14.12.2016 / 12:13
3

Change this:

$('img').error(function () {

});

So:

$('img').on('error', function () {

});
    
14.12.2016 / 12:15