Reputation: 6073
Okay ... I always thought that escaping apostrophe would allow you to use it in a JavaScript string and not break your quotes.
However, I have the following JavaScript call:
<a class="btn btn-danger" onclick="deleteAgenda(2056, 'PJ's Happy 4th of July New Agenda', '7/20/2017 5:15:00 PM');">
And I am getting an error:
Uncaught SyntaxError: missing ) after argument list
It fails in both Chrome and IE.
If I make the same call without the escaped apostrophe, it works.
If I cannot use an escaped apostrophe in a JavaScript String, how am I supposed to escape it?
Thanks,
Philip
Upvotes: 0
Views: 159
Reputation: 42304
That's because you are attempting to use HTML character entities from within JavaScript. All you need to do to escape an apostrophe in JavaScript is to preface the apostrophe with a backslash ('PJ\'s ... '
):
function deleteAgenda(one, two) {
console.log(two);
}
<a class="btn btn-danger" onclick="deleteAgenda(2056, 'PJ\'s Happy 4th of July New Agenda', '7/20/2017 5:15:00 PM');">Hi there</a>
Hope this helps! :)
Upvotes: 2