without quotation marks enough to pass a javascript html string

Asked

Viewed 94 times

0

I am 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 the <td onclick="remove('+***+')">

1 answer

1


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(\''+***+'\')">';
  • Thank you very much! Solved right. Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.