Print Special Characters like the Copyright Symbol using JavaScript

To print special characters like the Copyright symbol © or a Trademark ™ using JavaScript, use escape sequences.

For example, to print the Copyright symbol ©, use this code:

<html xmlns="http://www.w3.org/1999/xhtml" >
<
head>
<
title>Print Special Characters using JavaScript</title>
</
head>
<
body>
<
div id="divOne" />
<
script type="text/javascript">
var
str = "Copyright \u00A9 DevCurry.com";
document.getElementById('divOne').innerHTML = str;
</script>
</
body>
</
html>

Check some more Character Entity References over here. Note that escape sequences in JavaScript begins with a backslash character (\) like \u00A9 and so on.

OUTPUT

image






About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

2 comments:

Beben said...

hihihi
thanks a lot my friend ^^

Anonymous said...

exactly what i need - thanks!