tags:

views:

34

answers:

2

I have the following string:

'You've just created'

When I assign this string to a JavaScript variable, this is interpreted as 2 strings because there's a ' character.

How can I escape it?

+2  A: 

In JS code blocks, use a backslash:

var text = 'You \'ve just created'

in JS inside HTML, use a HTML entity:

<a onclick='alert("You &apos;ve just created");'>
Pekka
+2  A: 

You can use either " or ' to quote a string, so you could do it this way:

"You've just created"

or you can use a \ to quote just one character:

'You\'ve just created'
Ferruccio