/    Sign up×
Community /Pin to ProfileBookmark

losing newlines when inserting ajax result into div

In an ajax call I request a text block(formatted with newlines) from the database. I confirmed its still formatted in the database and in the return ajax result(using firebug). But as soon as I do the following, all the newlines are stripped out:
doc.getElementById(‘myDiv’).innerHTML = myTxt.textContent

The div is defined as:
<div id=”myDiv” style=”display:inline”></div>

I’m wondering if there is a property of the div or in the way I am inserting that could help fix the problem. I did read on this forum that people frown on using .innerHTML. If not using it will fix this problem I’ll gladly change it to the correct method(whatever that may be).

Your help is appreciated.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@mrhooAug 02.2008 — myTxt.textContent=myTxt.textContent.replace(/n/g,'<br>');
Copy linkTweet thisAlerts:
@kevincw01authorAug 02.2008 — i hate how obvious that is after seeing it. Thanks.
×

Success!

Help @kevincw01 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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