Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass this and string as parameter in jquery function

I try to append this following tag which has an onclick function.

 $("body").append('<img onclick="removeDynamicColumn(this,'someString')" src="css/images/builder/removeTDTR.png"/>');

In this function I am passing two parameters one is, the element itself and another one is string , if I enclose that string parameter with single quotes in JSP itself showing this error -

Syntax error on token "someString", invalid AssignmentOperator.

If I enclose with double quotes while calling that function I got this error -

SyntaxError: expected expression, got end of script

like image 673
hardcode Avatar asked Dec 02 '22 13:12

hardcode


1 Answers

Missing Escape '\' character in your code.

Try that code;

$("body").append('<img onclick="removeDynamicColumn(this,\'someString\')" src="css/images/builder/removeTDTR.png"/>');
like image 107
muratoner Avatar answered Dec 31 '22 23:12

muratoner