Typeerror: $(...). error is not a Function

Asked

Viewed 976 times

2

I have an error code in the latest version of jQuery v3.1.1 In version 1 there is no error. Here’s 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);
});

Documentation of the error: documentation here

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 jQuery.

3

Change this:

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

});

That’s why:

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

});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.