If you have inserted your img with innerHTML, like: $("div").innerHTML = , you can load another image if it fails doing, e.g, this:
Why is javascript: _needed? Because scripts injected into the DOM via script tags in innerHTML are not run at the time they are injected, so you have to be explicit.