JSFiddle - React, Tailwind, and code Playground

by railville

HTML

<div id='content'></div>

JavaScript

var text = "test text";
var imageTest = $("<img>");
imageTest.attr('src', 'http://dummyimage.com/305').load(function () {
  alert("image exists");
  var img = $('<div/>').append(imageTest.clone()).html(); // get it as a String
  $("#content").html(img + text); // <-- move it here - if loaded successfully add it
}).error(function () {
  alert("image doesn't exist");
  imageTest.remove(); // <-- don't need this since it's not even in the dom
  $("#content").html(text); // <-- move it here - if failed then just add text
});