I want to replace text with an image using jQuery. I have been using the .replace function to replace text with more text. How would I replace the text with an html tag, like an <img> tag.
Here is my code:
function wow() {
$('.messageBody').each(function() {
var text = $(this).text();
var image = '<img class = "emote" src = "trump.png">'
$(this).text(text.replace(':trump:', image.outterHTML));
});
}
setInterval(wow, 1000);
Here is the HTML:
<span class="messageBody">:trump:</span>