If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

When the button is clicked, the text of testdiv2 doesn't change on the browser, but the text of testdiv changes to "xViantU". And, the alerts come back as "xViantU" and "xViantU&ampCOutpatient", respectively.

I don't understand why the "&" gets converted to "&amp" for the 2nd, but not for the 1st. Any light shed on this is appreciated -- thanks.

After some experimentation, I've discovered what's going on. It appears to be a JS behavior that's specific to IE (IE8, and possibility previous versions).

If you have a string that contains an ampersand, and you assign that string to the value of an element's innerHTML, JS will automatically convert the "&" to "&amp;" in the new innerHTML value. BUT, it will do this ONLY if the ampersand in the string is followed by at least 11 characters. Any less than 11, it will not, and will likely truncate the ampersand and everything that came after it (unless the ampersand is already being used in a character code.)

Not sure why IE8 behaves this way. In Firefox, the number of chars following the ampersand doesn't matter; JS in FF will convert "&" to "&amp;", regardless. (Again, as long as the ampersand isn't being used in a character code).

Have you looked at the escape and unescape and the encode & decodeURI functions?

Yes - looked at all 4 before posting here:

escape() - is url-safe but not html-safe. escape("foo&bar") = foo%26bar. Function is also deprecated.
unescape() - No effect, and is also deprecated.
encodeURI() - Doesn't handle special characters like "&" -- for that you need to use encodeURIComponent().
encodeURIComponent() - Same problem as escape() -- url-safe but not html-safe.
decodeURIComponent() - no effect.

There's no function native to JS that does what I need done, so I just ended up using the replace() function, since I know the beginning string will always have "&" as and not "&amp;".