Search code examples
javascriptquotes

Single quotes in javascript function?


I have created my table dynamically and in one of my td's I have function where I'm passing two different parameters. One of them is ID and does not need quotes around but second parameter need single quotes and I tried so many combinations like "e; or \' and I could not get what I need. Here is my code:

tbl +="<td><a onClick='DeleteRes(slotsPtc,"+jsData[key].res_ID+")'></a></td>

Code above gave me this:

<a onclick="DeleteRes(slotsPtc,327)"></a>

I'm missing single quotes around first parameter slotsPtc if anyone can help how I can put single quotes around that parameter please let me know. Thanks.


Solution

  • You can use &apos; (or &#39;) as a single quote in HTML:

    tbl += "<td><a onClick='DeleteRes(&apos;slotsPtc&apos;,"+jsData[key].res_ID+")'></a></td>";