Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
keep apostrophes when passing string value in Innerhtml

The text value holds string text with double quotes and apostrophes as you see in the example. when I print the result it changes to different characters.

The text that is coming from API is :

"mismatched input 'STARTt' expecting 'START' ";

but when I print it, it goes :

"mismatched" input="" 'startt'="" expecting="" 'start'=""

I would like to print the string exactly how is stored

  
  var marker = document.createElement("div");
  
  var text = "mismatched input 'STARTt' expecting 'START' ";
  
  marker.innerHTML = "<div data-tooltip=" + text+ ">⚠️</div>";



console.log(marker.innerHTML);

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You need to wrap text with quotes.

This works for me:

marker.innerHTML = "<div data-tooltip=\"" + text+ "\">⚠️</div>";

about 4 years ago · Juan Pablo Isaza Relatório

0

Attribute values containing spaces have to be delimited with " or '.

Attribute values containing ' have to be delimited with "

Attribute values containing " have to be delimited with '.

Attribute values containing " and ' have to be delimited with one of those while the other has to be replaced with the appropriate entity (&quot; or &apos;).


Trying to generate HTML by mashing strings together is asking for trouble when you hit any kind of escaping requirements.

Don't do it. Use DOM methods instead.

const marker = document.createElement("div");
const text = "mismatched input 'STARTt' expecting 'START' ";
const child = document.createElement('div');
child.setAttribute('data-tooltip', text);
child.innerText = "⚠️";
marker.appendChild(child);
console.log(marker.innerHTML);

about 4 years ago · Juan Pablo Isaza Relatório

0

Use a template string. It should solve the problem

  var marker = document.createElement("div");
  
  var text = `mismatched input 'STARTt' expecting 'START' `;
  
  marker.innerHTML = `<div data-tooltip=" + text+ ">⚠️</div>`;



console.log(marker.innerHTML);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda