[Javascript] createTextNode and special characters

J. Lester Novros II lester at denhaag.org
Sat May 25 20:09:45 CDT 2002


Dear Normann,

On 05/24/2002 03:33 PM, Immanuel Normann wrote:
> I want to create dynamically text with special characters like ä
> Therefore I want to use document.createTextNode('ä');

Ah, took me a while to figure that one out. 'createTextNode' does exactly what 
it says, it creates a *text* node. The '&foo;' notation, however, is an HTML 
construct and is not interpreted as such in a text node. What you want is the 
'innerHTML' property of the node, like this:

    var t = document.createElement('div');
    t.innerHTML = 'ä';
    document.body.appendChild(t);

Then, the '&foo;' construct *is* interpreted as HTML which will yield the 
desired result.

l8R lES
-- 
Sharing information with competitors can damage national security. [...] Some m$
code is so flawed it cannot be safely disclosed.
                         m$ vice president Jim Allchin in Federal Court testimony
http://open.denhaag.nu                                    http://www.denhaag.org




More information about the Javascript mailing list