codfish555
codfish555

Reputation: 96

How can I add a html unicode onto createTextNode

So I've got a span

<span class="delete-btn">&#x2718;</span>

and am trying to include the HTML unicode for x - &#x2718; within a textNode -

span.appendChild(document.createTextNode("&#x2718;"));

however this simply isn't working. Any ideas?

Upvotes: 4

Views: 2082

Answers (1)

Zenoo
Zenoo

Reputation: 12880

You can simply use \u2718 :

let span = document.getElementsByClassName('delete-btn')[0];
span.appendChild(document.createTextNode('\u2718'));
<span class="delete-btn">&#x2718;</span>

Upvotes: 5

Related Questions