Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
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

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Missing Escape '\' character in your code.

Try that code;

$("body").append('<img onclick="removeDynamicColumn(this,\'someString\')" src="css/images/builder/removeTDTR.png"/>');
about 4 years ago · Santiago Trujillo Report

0

Try escape \

 $("body").append('<img onclick="removeDynamicColumn(this,\'someString\')" src="css/images/builder/removeTDTR.png"/>');
about 4 years ago · Santiago Trujillo Report

0

let's assume we have an string in a variable like this:

var param = "somestring"

we can inject this variable to your example, this way:

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

G.L

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!