Ankit Sahu
Ankit Sahu

Reputation: 85

How to use single and Double quote in javascript

$("<button class='btn btn-success' onclick='commentupload("+foo.id+","+uname+","+name+")' style='margin-top:5px;align:left'>")

This the code of jquery which i am using to generate this button dynamically. i need to pass the 3 argument 1st one is integer so there is no problem with that but the 2nd and the third parameter contains string so it requires ' before and after. But i am unable to implement that.

Please help me with this...

Upvotes: 0

Views: 55

Answers (2)

Natrium
Natrium

Reputation: 31204

You need to escape the quotes.

$("<button class='btn btn-success' onclick='commentupload(" + foo.id + ", \"" + uname + "\", \"" + name + "\")' style='margin-top:5px; align:left;'>")

Upvotes: 1

user4868160
user4868160

Reputation:

you can use this to handle it.

$("<button class='btn btn-success' onclick='commentupload(" + foo.id + ", \"" + uname + "\", \"" + name + "\")' style='margin-top:5px; align:left;'>")

Upvotes: 1

Related Questions