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

230
Visualizações
Storing HTML in a JS variable but preserving the HTML variables

Im trying to save some HTML in a JS variable by using the backtick formatting however is it possible to preserve the HTML variable according to the following example

var msg = "This is a test" + "\n" + "Test"

Im attempting to store this variable as a HTML paragraph while keeping the linebreaks

var emsg = '<p style="white-space: pre-wrap;"><\"{msg}"\</p>'

But when sending that content in an email to myself (Using Emailjs) I get the following

<"{msg}"

Any clue what I'm doing wrong? Thanks!

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

0

  1. You are using single quotes ('), not backticks (`)

  2. Placeholders in template literals are indicated by a dollar sign ($), which you are missing.

var msg = "This is a test" + "\n" + "Test"

var emsg = `<p style="white-space: pre-wrap;"><\"${msg}"\</p>`

console.log(emsg)

about 4 years ago · Juan Pablo Isaza Relatório

0

You could go with template literals like @spectric showed. or you can go with simple quote using + to seperate it with msg variable

var msg = "This is a test" + "\n" + "Test";//    V     V
var emsg = '<p style="white-space: pre-wrap;"><\"'+msg+'"\</p>';
console.log(emsg);
about 4 years ago · Juan Pablo Isaza Relatório

0

as described + removing the extra <\" and "\ probably

var emsg = <p style="white-space: pre-wrap;">${msg}</p>

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