Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
67
rated 0 times [  74] [ 7]  / answers: 1 / hits: 144277  / 13 Years ago, mon, june 6, 2011, 12:00:00

I'm doing some stuff with javascript and I'm wondering, how do I put an apostrophe in a string in javascript?



theAnchorText = 'I apostrophe M home';

More From » javascript

 Answers
31

You can use double quotes instead of single quotes:



theAnchorText = I'm home;


Alternatively, escape the apostrophe:



theAnchorText = 'I'm home';


The backslash tells JavaScript (this has nothing to do with jQuery, by the way) that the next character should be interpreted as special. In this case, an apostrophe after a backslash means to use a literal apostrophe but not to end the string.



There are also other characters you can put after a backslash to indicate other special characters. For example, you can use n for a new line, or t for a tab.


[#91843] Friday, June 3, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emilee

Total Points: 365
Total Questions: 113
Total Answers: 109

Location: Monaco
Member since Fri, Sep 24, 2021
3 Years ago
;