I
I
Isaac Clark2015-03-15 20:02:01
JavaScript
Isaac Clark, 2015-03-15 20:02:01

How to add unicode string to html via javascript?

Hello, tell me please.
The & symbol in Unicode is "&" + "#38;" , if I directly enter it into html:
<div id="div" title="&#38;"></div>
Then in the end I get this result:
<div id="div" title="&"></div>
Everything is super! BUT!
If I want to add unicode with js:

var div = document.getElementById('div');
div.setAttribute('title', "&#38;");

That result turns out here such:
<div id="div" title="&#38;"></div>
Why so? How to make it so that when adding unicode to html using js, the result is:
<div id="div" title="&"></div>
Thanks for your help and your time.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vgbege, 2015-03-15
@Dark_Knight

div.setAttribute('title', "\u0026");

K
keslo, 2015-03-15
@keslo

Can't you do that?

var div = document.getElementById('div');
div.setAttribute('title', "&");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question