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

Appending symbol code to HTML from a JS function

I am trying to append a html symbol code – ☀ which is a sun to an html span.innerHTML using a js function but what I get in is

<span class="condition symbol">&amp;#x2600;</span>

And in this way it shows ☀ instead of the sun symbol.

I tried using “, ”,"" while appending the symbol’s code but same.

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

const htmlElement=document.createElement('span');
... //adding the classes
htmlElement.textContent='&#x2600;';

>Solution :

Use innerHTML instead of textContent to render the symbol.

const htmlElement=document.createElement('span');
//adding the classes
htmlElement.innerHTML='&#x2600;';
document.body.append(htmlElement);
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