as this question is the first result at search engines
There are a problem with the selected -and right by the way- solution, is that if you want to add style that will apply to images like ( borders for example ) .
for example :
img {
color:#fff;
border: 1px solid black;
padding: 5px;
background-color: #ccc;
}
as you can see, all of images will apply the same style
there is another approach to easily work around such an issue, using onerror and injecting some special class to deal with the interrupted images :
.invalidImageSrc {
color:#fff;
border: 1px solid black;
padding: 5px;
background-color: #ccc;
}