Reputation:
When i click the following it fails.
php render/html:
<div class="a" onclick="test('25', 'l'Espagne')" >
js:
function test(id, name) {
alert(name);
}
Upvotes: 1
Views: 259
Reputation: 29
You'll need to escape it with a back slash "\". For example,
test('25', 'l\'Espagne')
For more information on escape characters, see
Source: https://stackoverflow.com/a/21672439
Upvotes: 1
Reputation: 42089
You can use template literals if you're not worried about supporting old browsers (incl. IE):
function test(id, name) {
alert(name);
}
<div class="a" onclick="test('25', `l'Espagne`)">Click Me</div>
Upvotes: 2
Reputation: 32511
You can escape the quote mark with a \ whenever you need a single quote inside of a pair of single quotes. This also works for double quotes, if needed.
function test(id, name) {
alert(name);
}
<div class="a" onclick="test('25', 'l\'Espagne')">Click Me</div>
Upvotes: 4