Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<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?

>Solution :

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>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading