JSFiddle - React, Tailwind, and code Playground

HTML

<div class="broken"></div>
<div class="works"></div>

JavaScript

var broken = $(document.createElement('img'));
broken.attr('src', 'http://www.idontexistsimage.com');

var works = $(document.createElement('img'));
works.attr('src', 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSHcq7LGf94uVige9J17eW_fyIrOHJvXTpXzBWi6CFRMxlm_kXP');

$('.broken').first().append(broken);
$('.works').first().append(works);

$( "img" ).error(function() {
    $( this ).click(function() { 
    alert('Image does not exist!'); 
  });
});