Html entities must be encoded in alt attribute of an image in HTML page. So
<img id="formula" alt="A → B" src="formula.png" />
will work well.
On the other hand, the same JavaScript code will not work
document.getElementById('formula').alt = 'A → B';
and will produce A → B instead of A → B.
How to do it through JavaScript, when it is not possible to put the special (unencoded) characters in the source code?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…