Character Entity References & DOM

  • Thread starter User Axes Dean Eyed
  • Start date
U

User Axes Dean Eyed

The following statement does not yield what I expect it to:

var txtNode = document.createTextNode("ESI−");

txtNode holds a value of "ESI−" instead of "ESI-" where '-' is the
character entity reference for the minus sign, that I expect.

I have tried other variations. I am working with Mozilla and IE because I
want to make NO use of extensions/browser-dependent code, and both (try to)
implement the DOM to varying degrees.

Searches of keyword sets:

createTextNode "character entity" HTML

and the permutations have not been helpful.

Does anyone know the secret?
 
M

Michael Winter

The following statement does not yield what I expect it to:

var txtNode = document.createTextNode("ESI−");

txtNode holds a value of "ESI−" instead of "ESI-" where '-' is the
character entity reference for the minus sign, that I expect.

This is discussed in the Specification:

<URL:http://www.w3.org/TR/DOM-Level-2-Core/introduction.html#ID-E7C30824>

As the extended intefaces mentioned in that section are directed at XML
documents, I don't think it's possible to include an entity reference in
the way you want. Your best bet is to look up the numeric values of the
entities (<URL:http://www.w3.org/TR/html4/sgml/entities.html>) and use
JavaScript string escape sequences. Numeric codes below 255 can be
specifed in hexadecimal using \xNN. Other characters must use the Unicode
hexadecimal sequence, \uNNNN. These are provided in the reference above
within the entity comments (look for U+NNNN). Your code above would be:

var txtNode = document.createTextNode("ESI\u2212");

[snip]

Hope that helps,
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top