2

In all versions of IE (I'm testing IE11 at the moment) new line breaks inside of textarea elements aren't working...

function id_(id)
{ 
 var r = false;
 if (document.getElementById(id))
 {
  r = document.getElementById(id);
 }
 return r;
}

window.onload = function()
{
 for (i in document.getElementsByTagName('audio')[0])
 {
  id_('test').value = id_('test').value + '\n' +i;
 }
}

How can I force IE to break lines in a textarea element? No frameworks.

I've tried \n\r, \r\n, \r and \n.

John
  • 1
  • 13
  • 98
  • 177

3 Answers3

5

After minimizing the code the issue was the CSS white-space property which I fixed with the code below.

* {white-space: nowrap;}
textarea {white-space: pre;}
John
  • 1
  • 13
  • 98
  • 177
  • 2
    It's really strange that IE ignores line feeds when white-space is set to `nowrap`. I've tried Chrome, Firefox, Safari, and Opera, and only IE shows this behavior. According to http://www.w3.org/wiki/CSS/Properties/white-space, line breaks *should* be suppressed for `nowrap`, so is it possible that IE is the *only* browser to get this right? – Rick Hitchcock Sep 22 '14 at 18:22
  • 1
    Even though we all hate IE I have to admit when they DO make an effort to interpret things correctly they really do well at doing so. Case in point when they took on `border-radius` (http://blogs.msdn.com/b/ie/archive/2010/03/19/the-css-corner-about-css-corners.aspx). – John Sep 22 '14 at 20:04
  • 1
    Thanks very much. Safari has just started doing this, so I was very grateful to find a solution. – SarahR Oct 20 '14 at 23:38
3

In IE, \n does indeed generate line breaks in textarea elements. That is, this code:

<textarea id="target">default text here</textarea>
<script>document.getElementById('target').value = 'a\nb';</script>

does, in IE, result in a textarea which holds the value default text here for an unimaginably short time followed by the value:

a
b

If you really want to test your browser, I have put this on a JSFiddle at: http://jsfiddle.net/91mj2arh/

CR Drost
  • 9,637
  • 1
  • 25
  • 36
1

This Fiddle based on your code adds line feeds in my version of IE11, and it seems to accomplish what you're looking for to iterate the audio element's properties:

http://jsfiddle.net/ff5kqtru/5/

If you post your HTML, we may be able to spot a problem.

Rick Hitchcock
  • 35,202
  • 5
  • 48
  • 79