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



Will you give this article a +1 ? Thanks in advance


About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 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!