I want to pass three parameters to this onclick()
function. but it gives me a syntax error.
element += '<div class="cancel" onclick="remove_game(' + game.id + ',\'' + cellstyle + ',\'' + cellid +'\');">';
It calls the function correctly, but it gives the error below
SyntaxError: missing ) after argument list
remove_game(6,'2, 'game6-cell2);
How can i resolve this issue?
I want to pass three parameters to this onclick()
function. but it gives me a syntax error.
element += '<div class="cancel" onclick="remove_game(' + game.id + ',\'' + cellstyle + ',\'' + cellid +'\');">';
It calls the function correctly, but it gives the error below
SyntaxError: missing ) after argument list
remove_game(6,'2, 'game6-cell2);
How can i resolve this issue?
Share Improve this question edited Apr 6, 2015 at 21:25 Kalle Richter 8,78729 gold badges93 silver badges207 bronze badges asked Apr 6, 2015 at 19:45 NeeroNeero 2262 gold badges7 silver badges23 bronze badges2 Answers
Reset to default 4Your '
's and mas are off, so that the second argument appears to be '2, '
, and then there isn't a ma before the third. Assuming you want quotes around the 3rd argument, you'd need something like this:
element += '<div class="cancel" onclick="remove_game(' + game.id + ',' + cellstyle + ',\'' + cellid +'\');">';
Tada
var element = document.createElement('div');
element.className = 'cancel';
element.addEventListener('click', function() {
remove_game(game.id, cellstyle, cellid);
}, false);