Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-17-2004, 05:07 PM   PM User | #1
mothra
Regular Coder

 
Join Date: Jul 2003
Posts: 262
Thanks: 1
Thanked 0 Times in 0 Posts
mothra is an unknown quantity at this point
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.
mothra is offline   Reply With Quote
Old 05-17-2004, 05:57 PM   PM User | #2
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
thisLi.firstChild.nodeValue

perhaps?
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 05-17-2004, 08:19 PM   PM User | #3
mothra
Regular Coder

 
Join Date: Jul 2003
Posts: 262
Thanks: 1
Thanked 0 Times in 0 Posts
mothra is an unknown quantity at this point
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.
mothra is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:15 AM.


Advertisement
Log in to turn off these ads.