Hello, tell me how you can implement this! If a user inserted a combination of characters into a block with text;) for example, this was replaced by a picture (emoticon). It is advisable to do this on jquery messages, the messages will be constantly loaded. Thank you in advance!

    2 answers 2

    Here is a sample code for replacing characters: jsfiddle .

    var text = 'hi all! :)'; function replaceEmotion (text) { var newText = text.replace(/:\)/g, '<img width="23" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQCp1ny3sdYH4gFBlHFLEpvJcIiMq1VtZE1SiAjoe8B4AoPqbXd">'); return newText; } document.body.innerHTML = replaceEmotion(text); 

    The point is to take each message and look for the right combination of characters in it, replacing it with a picture tag (for example).

    This code can be expanded by creating an array of combinations of characters and their replacement.

      It is better to send a message to the server using ajax and process it on the server side. In general, it is not clear what you want to get.