View Full Version : innerHTML returns additional chars

05-17-2004, 06:07 PM
I'm finding that innerHTML is returning some 'extra' chars, probably a carriage return and or line feed on certain elements (such as <li>). IE and Mozilla handle this in different ways of course.

alert(thisLI.innerHTML + "FOO") ...In IE returns:
"Hello FOO"

alert(thisLI.innerHTML + "FOO") ...In MOZ returns:

It's funny though that in MOZ I can concat the above result with another string (such as "Hello FOOBAR") and it's like the line feed (or whatever) is not there. In IE it appears as a space in the concatenated string ("Hello FOO BAR")). So I have tried: thisLI.innerHTML.replace("\n","") and also "\r", "\n\r", "\r\n", etc... which have not worked.

I can use substring() to trim off the last char(s) but it's cludgy, trimming only 1 char makes it work in IE & MOZ but trimming more than 1 char causes mixed results. I know there are multiple chars on the end just not what they are and what the best way to get rid of them is. Can anyone suggest something?

Thank you.

05-17-2004, 06:57 PM


05-17-2004, 09:19 PM
Thanks, but it wasn't what I was looking for. Seemed to add another carriage return that way. I was trying to use charCodeAt and fromCharCode to determine what the offending chars are but I didn't have any luck so for now I'm going to use substring() and trim 1 char off the length.