How to set id= with ' instead of "

Asked

Viewed 61 times

0

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

html/javascript code

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

The problem is in the id="idteste" which has the "" and when it is put in the c# of the error.

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

The script is very large and has several {} so I can’t do it:

Exemplo:

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

Not even that:

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

I need it to stay like this: 'idteste', does anyone know any solution? Thank you.

2 answers

0

Only changing the order of the tiles works. If that’s what I understand and you need the id to be in id='test format'

  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>
<div id="labelhm">
  <p></p>
  <p></p>
</div>

https://jsfiddle.net/h79whqu8/1/

  • I got it, it’s just that what runs the script here does not accept the '', so I did a trick and it worked, but thanks.

  • Ah got it, good that it worked. If you can share with us your solution there.

0


Reverse the apostrophe by quotation marks and vice versa right, but you use one escape \ javascript

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

Browser other questions tagged

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