Jonnyx Delavilla
Jonnyx Delavilla

Reputation: 565

rails turbolinks onerror javascript

I want to hide an image when the link of the image is broken (404 not found). When i trigger an onerror:hideImage(this) on my image it works once and then because of Turbolinks, it hides all the images after a refresh. Is there a solution?

function hideImage(source){
    source.hide();
}

Thanks

Upvotes: 1

Views: 390

Answers (1)

Jonnyx Delavilla
Jonnyx Delavilla

Reputation: 565

Ok, found the solution:

add onerror:"this.style.display='none'" to your image_tag and it's done!

Upvotes: 3

Related Questions