How do I hide broken images in javascript?

html, javascript

Solution

You can use the onerror handler. In the inline form, it looks like this:

<img src="someimage.jpg" onerror="this.style.display='none';" />

Problem

I have my image inside an if statement: ``` if (item.image) historyHtml += '<a href=' + item.image + ' class="image" target="_blank"><img src="' + item.image +'" width="111px"/></a>'; ```

Original source