JSFiddle - React, Tailwind, and code Playground

by kasdega

HTML

<div class="result">Hello World</div>

JavaScript

jQuery.fn.outerHTML = function(s) {
return (s)
? this.before(s).remove()
: jQuery("<p/>").append(this.eq(0).clone()).html();
}

$(document).ready(function() {
    var text = "some text to replace here.... text text text";
    var element = $('<img src="image">');
    
    $('.result').html(ReplaceWithObject(text, "here", element));
});
    
function ReplaceWithObject(textSource, textToReplace, objectToReplace) {
    return textSource.replace(textToReplace, objectToReplace.outerHTML());
}