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

304
Visualizações
How to use encoded HTML text within string literals?

I am trying to include a HTML encoded special character within a string literal, but it will not render as HTML in the final document.

I am trying to do it like such:

const head = { 
title: `${ApplicationName} - ${Slogan}™`
}

In the above code the ™ part it supposed to render a trademark symbol like ™. But when this code makes it into the HTML document it ends up rendering as a string:

<head>
  <title>Imaginary Inc - We straight don't exist&trade;</title>
</head>

Is there any way to get it to work, maybe using some kind of escaping technique?

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

0

You can use the unicode of the character to achieve this, add a backslash before the character unicode to denote this in JavaScript. (™ → \u2112)

const title = $("title");
title.append("\u2122");

console.log(title.text());
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<head>
  <title>My Title</title>
</head>

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use innerHTML or a DOM Parser with innerText

let t = document.querySelector('title');
let var1 = 'foo', var2 = 'bar'
let str = `${var1} - ${var2}&trade;`
t.innerHTML = str;
console.log(t)

let doc = new DOMParser().parseFromString(str, 'text/html');
t.innerText = doc.body.innerHTML;
console.log(t)
<title></title>

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