Replace a list of emoticons with their images

Posted by Damiano on Stack Overflow See other posts from Stack Overflow or by Damiano
Published on 2010-06-16T17:03:17Z Indexed on 2010/06/16 17:12 UTC
Read the original article Hit count: 269

Filed under:

Hello, I have an array with:

emoticons = {
   ':-)' : 'smile1.gif',
   ':)'  : 'smile2.gif',
   ':D'  : 'smile3.gif'     
}

then i have a variabile with the text.

var text = 'this is a simple test :)';

and a variable with the url of the website

var url = "http://www.domain.com/";

How to write a function that replace the symbols with their images?

The <img> tag result should be:

<img src="http://www.domain.com/simple2.gif" />

(I have to concatenate the url varible to the name of the image).

THank you very much!

© Stack Overflow or respective owner

Related posts about JavaScript