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">&#x2600;</span>
And in this way it shows ☀ instead of the sun symbol.
I tried using “, ”,"" while appending the symbol’s code but same.
const htmlElement=document.createElement('span');
... //adding the classes
htmlElement.textContent='☀';
2
Answers
Use
innerHTML
instead oftextContent
to render the symbol.As mentioned, you can use innerHTML to display the symbol.
Or you can also use textContent and set the hexadecimal content like this