How do i display a string with Special Characters like € in a Javascript/jQuery alert?
eg: I want to display a message box with "The Price is €10"
But when i use the below code:
alert("The Price is €10");
The Output shown in the message box is "The Price is €10"
, I want my output to be "The Price is €10"
.
Can some help me with this please? Thanks in advance.
The native
alert
method does not decode HTML encoded entities.But browsers do while rendering HTML. One hack is to create a HTML element with the specific text as its
innerHTML
(so it does the character processing), then get back itstext
property and alerting it out.This will work for all &xxx characters that the browser can display, without needing to find out the character code for each special character you may want to use.
Use this as the alert. Works fine for me.
The description is here : http://leftlogic.com/projects/entity-lookup/
Check :
http://jsfiddle.net/Nseum/
Unicode Character 'EURO SIGN' (U+20AC)