without quotes enough to pass a javascript html string

1

I'm facing a difficulty, I have to create tags, which will have a function when clicking, the problem is that, I have to pass a string in the element in html ie when calling the function and pass as parameter, I need to use quotes, but ended the options in javascript.

document.getElementById('table').innerHTML += '<tr id="'+obj[i].id+file+'"><td>'+obj[i].id+'</td><td>'+obj[i].name+'</td><td align="center" valign="top"><img src="'+obj[i].picture+'"/></td><td><button onclick="remove('+obj[i].id+file+')">Excluir</button><br/><button onclick="Alterar('+obj[i].id+')">Alterar</button></td></tr>';

the specific element is in <td onclick="remove('+***+')">

    
asked by anonymous 16.08.2018 / 14:36

1 answer

2

Just escape the character, this is done using the backslash "\". So it would look like this

document.getElementById('table').innerHTML += '<tr id="'+obj[i].id+file+'"><td>'+obj[i].id+'</td><td>'+obj[i].name+'</td><td align="center" valign="top"><img src="'+obj[i].picture+'"/></td><td><button onclick="remove(\''+obj[i].id+file+'\')">Excluir</button><br/><button onclick="Alterar('+obj[i].id+')">Alterar</button></td></tr>';

Or as in your example

<td onclick="remove(\''+***+'\')">

For example, adding something to the table

document.getElementById('table').innerHTML = '<td onclick="remove(\''+***+'\')">';
    
16.08.2018 / 14:58