How to set the id = with 'instead of'

0

How can I set the id = with 'instead of' because if I try to run the script in chromeBrowser.ExecuteScriptAsync with the id="" it error, how can I do that?

html code / javascript

var x = '<label id="idteste">Testando' +
        '</label></div>'
$('#labelhm p:first').html(x);

The problem is in the id="idteste" that has the "" and when put in the error #.

I have tried "+" idteste "+" which takes the error, but then the error in the script saying that the id is not valid

The script is very large and has several {} so I can not do this:

Exemplo:

chromeBrowser.ExecuteScriptAsync("id={}", "idteste");

Not even that:

chromeBrowser.ExecuteScriptAsync($"id={idteste}");

I need it to look like this: 'idtest', does anyone know a solution? Thank you.

    
asked by anonymous 30.05.2018 / 19:23

2 answers

0

Invert the apostrophe by quotation marks and vice versa, but you use an escape \ javascript

  var x = '<label id=\'idteste\'>Testando' +
      '</label></div>'
  $('#labelhm p:first').html(x);
    
30.05.2018 / 19:40
0

Just changing the order of quotes works. If this is what I understood and need the id to be in the format id = 'test'

  var x = "<label id='idteste'>Testando" +
      "</label></div>"
  $('#labelhm p:first').html(x);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><divid="labelhm">
  <p></p>
  <p></p>
</div>

link

    
30.05.2018 / 19:36