0

I have attempted escaping quotes out from this jquery bit of code and I'm not quite getting it. As well as the correct answer could I get the format for escaping quotes in jquery? Specifically I'm only trying to put the rdata.result[i].name variable into a string to pass it over. Thanks!

filling += "<a onclick=\"inserttictac("+rdata.result[i].uid+","+rdata.script[0]+",\'"+rdata.result[i].name+"\',"+rdata.result[i].front+","+rdata.result[i].back+","+rdata.result[i].side+")\'>Select</a>"; 
1
  • 2
    You could probably make your life easier if you didn't use inline Javascript, but instead defined the handler with $("selector").click(). Commented Nov 28, 2013 at 12:31

1 Answer 1

2

You don't need to escape the single quotes, only the double quotes.

You are using double quotes for string definition, so only escape those.

filling += "<a onclick=\"inserttictac("+rdata.result[i].uid+","+rdata.script[0]+",'"+rdata.result[i].name+"',"+rdata.result[i].front+","+rdata.result[i].back+","+rdata.result[i].side+")\">Select</a>"; 
Sign up to request clarification or add additional context in comments.

3 Comments

apparently I get this in the console: Uncaught SyntaxError: Unexpected string
escape it . other wise chars line " ' create issues
@user3045858 Try now, just noticed you were using a single quote for the end of your string concatenation. I've edited answer to double, with escape.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.