How do I nest quotes without JavaScript causing a runtime error?
You must escape them or alternate between single and double quotes. Take a look at the first example which uses alternating quotes.
<a href='#' onclick="alert('Hello')">About </a>
The following example uses the escape character (\) to let the JavaScript engine know that we want the quote printed and is not part of the syntax.
<a href='#' onclick="alert('How\'s your day?')">About </a>
Quotes can be escaped numerous times in any one statement. If you forget to escape your quotes, your scripts will fail. Take a look at this stipped down example :
'You\'re day\'s going well?'
Sometimes you need to print double quotes, in this case, you'd use something like the following :
"Click the link that says \"Start\""
Top