jQuery bookmarklet textnode not working

57 Views Asked by At
$('.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!

1

There are 1 best solutions below

0
On

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;'>")
);