Alt attribute encoding with JavaScript

Posted by MainMa on Stack Overflow See other posts from Stack Overflow or by MainMa
Published on 2010-05-05T17:13:27Z Indexed on 2010/05/05 17:18 UTC
Read the original article Hit count: 160

Hi,

Html entities must be encoded in alt attribute of an image in HTML page. So

<img id="formula" alt="A &rarr; B" src="formula.png" />

will work well.

On the other hand, the same JavaScript code will not work

document.getElementById('formula').alt = 'A &rarr; B';

and will produce A &rarr; 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?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about special-characters