Given is an input field with an code representing an emoji. I now want to replace this code with the corresponding emoji.
The idea was to substitute the value with the unicode but that does not work for me in inputs. Only when I copy the emoji itself into the code, the replacement works.
Example:
Given code: [e-1f60e]
,
converted: 😎
,
should be:
My question: how can I convert the given code to the emoji inside JavaScript?
$("#tauschen").click(function() {
$('#blub').val(function(index, value) {
return value.replace('[e-1f60e]', '😎'); // Doesn't work
});
});
$("#tauschen2").click(function() {
$('#blub2').val(function(index, value) {
return value.replace('[e-1f60e]', ''); // Works - but how to convert the given string to an emoji?!
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>
Given are strings in an imout field like these, representing an emoji: <strong>[e-1f60e]</strong> </p>
<p>
Now I want to display them "live" as emojis, instead of only the code: 😎
</p>
<input id="blub" type="text" name="test" value="[e-1f60e]">
<input type="submit" value="Test 1" id="tauschen">
<br>
<input id="blub2" type="text" name="test" value="[e-1f60e]">
<input type="submit" value="Test 2" id="tauschen2">
JSFiddle: https://jsfiddle.net/r07qnuoz/1/