Search code examples
javascriptasp.nethrefquote

how to put nested quote inside each other three times in (javascript and ap.net)


in this code in each loop it should create new href and give it id= (the number of o variable) but the problem that I put double quote inside single quote .

    for (o = 0; o < count; o++) {

 $('#'+o).prepend(' <td class="col-lg-2">' +

 '<a href="#" id="o"  onClick="Confirm()" runat="server"     
onServerClick="MyFuncion_Click" class="tableicontoolbar"datatoggle="tooltip"data-placement="top" title="Edit" > ' +
' <img src=\"../images/icon-edit.png\"></a> ' +
   ' </td>');
}

I tried many solution but none work


Solution

  • Just remove the \s, and ignore the fact that your string contains "s, they don't matter, and runat="server" and onServerClick has no purpose on the client side.

    for (o = 0; o < count; o++) {
     $('#'+o).prepend(' <td class="col-lg-2">' +
     '<a href="#" id="id_'+o+'" onClick="Confirm()"   
     class="tableicontoolbar" datatoggle="tooltip" data-placement="top" title="Edit">' +
    ' <img src="../images/icon-edit.png"></a> ' +
       ' </td>');
    }
    

    You could also remove the "s as they are not needed:

    for (o = 0; o < count; o++) {
     $('#'+o).prepend(' <td class=col-lg-2>' +
     '<a href=# id=id_'+o+' onClick=Confirm() 
    class=tableicontoolbar datatoggle=tooltip data-placement=top title=Edit>' +
    ' <img src=../images/icon-edit.png></a> ' +
       ' </td>');
    }
    

    Also note, that ID's can not be numeric. It may work in some browsers, but IDs can not begin with a number, so I've prefixed them with id_ for you.