Replace the Euro Symbol (€) using Javascript (jQuery)
I spent a while on Friday searching for a way to replace the Euro symbol (€) in content pulled from a text area, using Javascript (jQuery). As it took me some time to track down an answer, here it is:
var theContent = $('#theTextArea').val().replace(/\u20ac/g, 'Euro');
This replaces using a global search to find instances of the euro symbol, and replaces them with the word “Euro”. Using the actual Euro symbol (€) as the search pattern doesn’t work – so, for example, this won’t work:
.replace(/€/g, 'E');
Instead, this needs to be used: "\u20ac"