Insert Special Characters Using JavaScript

No.of Views2555
Bookmarked0 times
Downloads 
Votes0
By  ansari.najmul@gmail.com   On  24 Aug 2010 09:08:42
Tag : JavaScript , General
The backslash (\) is used to insert apostrophes, new lines, quotes, and other special characters into a text string.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

Before explaining the article, I would like to thank all readers who read my article and voted for it.Your appreciation for my article gives me strength to write more good articles. Hope in future I will get your valuable comments and suggestions.Now I won't waste your time and come back to the topic. I have written this article on ‘Insert Special Characters’. The backslash (\) is used to insert apostrophes, new lines, quotes, and other special characters into a text string.

Look at the following JavaScript code:

var txt="We are from "codegain" technical team;
document.write(txt);

 In JavaScript, a string is started and stopped with either single or double quotes. This means that the string above will be chopped to: We are the so-called To solve this problem, you must place a backslash (\) before each double quote in "Viking". This turns each double quote into a string literal:\

var txt="We are from\"codegain\" technical team.";
document.write(txt);

JavaScript will now output the proper text string: We are the so-called "Vikings" from the north.
Here is another example:

document.write ("You \& Us can improve our skills!");

The example above will produce the following output:
"You & Us can improve our skills!

Thanks.

 
Sign Up to vote for this article
 
About Author
 
ansari.najmul@gmail.com
Occupation-Software Engineer
Company-NetEdge Computing Solutions
Member Type-Fresh
Location-India
Joined date-12 Aug 2009
Home Page-dotnetlogix.com
Blog Page-
 
 
Other popularSectionarticles
    Comments
    There is no comments for this articles.
    Leave a Reply
    Title:
    Display Name:
    Email:
    (not display in page for the security purphase)
    Website:
    Message:
    Please refresh your screen using Ctrl+F5
    If you can't read this number refresh your screen
    Please input the anti-spam code that you can read in the image.
    ^ Scroll to Top
    </