You need to escape the character ('
) that is the same character as the "wrapper" ('
). You usually do this with a preceeding slash : \'
.
Therefore:
<button onclick='getAnsVoc("J\'ai attendu mon ami.", "Q2A",
"Q2B", "Q2C", "Q2D")'>Answer</button>
As an alterative you can also replace the character with it's HTML entity name. For '
you can use '
. Therefore:
<button onclick='getAnsVoc("J'ai attendu mon ami.", "Q2A",
"Q2B", "Q2C", "Q2D")'>Answer</button>
If you are playing with user submitted (or otherwise dynamic) data and you need to ensure that single ('
) and double ("
) quotes are correctly encoded to be "safe" in javascript then you need a function to "encode" these elements.
An example of this sort of functionality is at the bottom of the links list below:
Useful links: