2

I am using this jquery to add some elements of the page and add them to a text area

$('#chk_editor').append($('#greeting').text()).append('\n \nI want it to be known that').show();

Internet Explorer ignores the /n, I found this question that addresses the issue with split() Javascript split() not working in IE

I'm not sure how to implement it into my code, any help appreciated.

Community
  • 1
  • 1
Nik
  • 671
  • 1
  • 8
  • 27

3 Answers3

4

Try using \r\n.

This is the Windows style line ending. \n is the UNIX style line ending.

Andrew Jackman
  • 13,781
  • 7
  • 35
  • 44
  • I understand this is the most succinct answer, the answer I ticked allowed me to work more flexibly with the code which was a little bonus. – Nik Feb 06 '13 at 08:06
  • Sorry until I opened windows xp, worked well in windows 7, your answer works in both.. – Nik Feb 07 '13 at 10:21
2

Try the following:

    var text = $("#chk_editor").val();
    text = text + $("#greeting").html();
    text = text + "\n \n I want to be known.";
    $("#chk_editor").val(text);
Axel
  • 142
  • 1
  • 7
0

try one of those 2 options:

1) for any string that contain \n you can do somthing like:

  function adjustText(messageString)
 {
   return messageString.replace('\n', '\r\n');
 }
 ....
 $('#chk_editor').append($('#greeting').text()).append(adjustText(message));

see also https://stackoverflow.com/a/5899275/1219182

2) try to use the jquery-val() property (when setting textArea) instead of text()

$('#chk_editor').val("some text....\n ...bla bla \n...)

see also https://stackoverflow.com/a/5583094/1219182

Community
  • 1
  • 1
yoav barnea
  • 5,836
  • 2
  • 22
  • 27