/    Sign up×
Community /Pin to ProfileBookmark

Problem Rendering text in a div

Hi I have a code which is like this one:

<html>
<body>

<script type=”text/javascript”>
function changeText(){
document.getElementById(‘Stuff’).innerHTML = “<span style=”white-space:pre;” >”+”one line n enter n enter”+”</span>”;
}
</script>

<div id=”Stuff” style=”overflow: auto; min-height: 30px; white-space: pre;”>

</div>
<input type=’button’ onclick=’changeText()’ value=’Change Text’/>

</body>
</html>

It works fine. However on FF I am able to see 3 lines of my text (as expected) but on IE a see only I single long line, which is not what I wanted. Any idea?

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@tabzterMar 13.2008 — use <br /> instead of n
Copy linkTweet thisAlerts:
@toenailsinMar 13.2008 — IE is a douche with white-space as far as i know. using <br /> will be the best bet
Copy linkTweet thisAlerts:
@jlinkauthorMar 13.2008 — I am going to try that solution, the problem is that that text comes from a database. So I have to replace all n with <br />. thanks
Copy linkTweet thisAlerts:
@jlinkauthorMar 13.2008 — Another question, using the <br /> works fine. However since the size of my div is dinamically it there is a big big one line in the text that I am putting there then the div expands outer of the size of the container. Causing the layout to look ugly. The div has a overflow:auto but even with that it doesnt show the scrolls.
Copy linkTweet thisAlerts:
@toenailsinMar 14.2008 — if your using php, use nl2br(). it converts all the n's to <br />'s
×

Success!

Help @jlink 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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