Nik
Nik

Reputation: 671

\n is not working in IE text area

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.

Upvotes: 2

Views: 1620

Answers (3)

yoav barnea
yoav barnea

Reputation: 5994

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

Upvotes: 0

Axel
Axel

Reputation: 142

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);

Upvotes: 2

Andrew Jackman
Andrew Jackman

Reputation: 13966

Try using \r\n.

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

Upvotes: 4

Related Questions