Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2003
    Posts
    262
    Thanks
    1
    Thanked 0 Times in 0 Posts

    innerHTML returns additional chars

    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.

    <li>Hello</li>
    alert(thisLI.innerHTML + "FOO") ...In IE returns:
    "Hello FOO"

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

    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.

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    thisLi.firstChild.nodeValue

    perhaps?

  • #3
    Regular Coder
    Join Date
    Jul 2003
    Posts
    262
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •