0
$('.messages').children().each(function() { 
   var textNode = $(this); 
   textNode.text(
      textNode.text().replace("hi", "<img src='http://stupidknews.com/wp-content/uploads/2011/09/smiley-face.jpg' style='height:10px;'>")
   ); 
});`

I have that, it replaces the text in all classes with messages fine, but it replaces it with text, not with actual HTML.

How to make it work now!

iConnor
  • 19,997
  • 14
  • 62
  • 97
user43107
  • 97
  • 1
  • 1
  • 3

1 Answers1

0

You might need html() instead of text();

textNode.html(
   textNode.text().replace("hi", "<img src='http://stupidknews.com/wp-content/uploads/2011/09/smiley-face.jpg' style='height:10px;'>")
);
iConnor
  • 19,997
  • 14
  • 62
  • 97