MDanz Posted June 27, 2010 Share Posted June 27, 2010 I have a textarea and i am passing the text in it with javascript to a div. The problem is it is ignoring the line breaks and word wrapping. Is there anyway for the div to include word wrapping and line breaks? Quote Link to comment Share on other sites More sharing options...
Alex Posted June 27, 2010 Share Posted June 27, 2010 You need to convert literal line breaks, \n, into HTML line breaks, <br />. You can use the replace() method to do this. document.something.innerHTML = document.yourtextarea.value.replace("\n", "<br />"); Quote Link to comment Share on other sites More sharing options...
MDanz Posted June 28, 2010 Author Share Posted June 28, 2010 thanks for this.. but it doesn't seem to be working. i did this for example. e.g. test1 test5 test6 the result was in the div test1 test5 test6 any idea why? Quote Link to comment Share on other sites More sharing options...
haku Posted June 28, 2010 Share Posted June 28, 2010 Are you using php? if so, you should run the text through the nl2br() function before outputting it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.