Search code examples
javascripthtmlstringconcatenationgenerated

How to pass parameters to JavaScript Function From Generated HTML


    var html = html + "<tr>\n" + "<td style='text-align: center; background-color: #FFCE43;
'> </br>" + $(n).find("Julio").text() + " <img   style = 'cursor: pointer;' onclick='myFunction('"+a+"')' src='add.png'></td> </tr>";

I'm trying to pass the a as parameter but no success, i'm having trouble with combination of "", ''.


Solution

  • Replace with below code will work.

    var html = html + "<tr>\n" + "<td style='text-align: center; background-color: #FFCE43;
    '> </br>" + $(n).find("Julio").text() + " <img   style = 'cursor: pointer;' onclick='myFunction(\""+a+"\", \""+b+"\")' src='add.png'></td> </tr>";