Substitute function for jQuery’s . error() function

Asked

Viewed 395 times

2

I need to know what function to use instead of the function .error().

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

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

1 answer

-1


According to the official documentation:

From jQuery 1.8, the method .error() is depreciated. Use .on( "error", tratador) to attach event handlers to error event.

That is, change your code to:

$('img').on("error", function() {
    $('img').attr('src','img/erro.gif');
});
  • i tried this function, but it does not appear the image I put error

  • Right, but then your problem becomes another. Create a new question describing the new problem, your current code and more details of your problem (error messages, debugger behavior, code in more detail etc.)

  • @Pabloalmeida So the image doesn’t exist or her path is wrong.

  • I re-asked the question, but now this detailed https://answall.com/questions/251097/n%C3%A3o-estou-conseguir-a-imagem-que-demonstrar-erro-usando-jquery

Browser other questions tagged

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