/    Sign up×
Community /Pin to ProfileBookmark

Splitting innerHTML problem

I am able to get the contents of a <div> using the ‘.innerHTML’ DOM command.
When I try to split the contents into individual lines using the str.split(“n”) command
I get what I expect with FF (an array of individual lines),
but I get one massive long line in IE (appears to be a one element array?).

Does FF and IE handle the contents of .innerHTML differently?
I suspect that FF uses a “CRLF” while IE only uses “CR”, but I’m not sure.

If I’m right, how do I use the str.split() command to seperate the lines?

Is there a structure similiar to PERL that would look like str.split(/[n|r]/)?

Could I replace the <div> with <pre> and split the lines correctly for both FF and IE?

I’m running out of things to try. Any help is appreciated.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@hyperliskNov 22.2006 — You could try str.split(/[n|r]/) maybe with an 'i' flag. I always use the 'i' flag when I'm not sure... The RegExp's in JavaScript are pretty much the same as in Perl. So instead of using a string as the RegExp you could just use /pattern/flags
Copy linkTweet thisAlerts:
@JMRKERauthorNov 22.2006 — Thanks for the response. I'll give that a try.
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...