You are not the only one who has difficulty with line breaks in Javascript. I get a lot of questions about it, so hopefully this will help everyone out. If you come from a ColdFusion background, as I do, I think a lot of confusion comes from the fact that line breaks in ColdFusion are represented by the character 13 (new line character) followed by the character 10 (carriage return character)(ex. "#Chr( 13 )##Chr( 10 )#"). After dealing with this for so long, people instinctively try to replace out the same substring in Javascript text: "\n\r".
The problem is that in Javascript, line breaks are represented by the single new line character "\n", not the combination of new line and carriage return. To prove this, let's create a string in Javascript that uses the new line character "\n" to form multiple line:
var strMultiLineText =
Karen didn't know how to feel any more. She had never liked girls\n" +
"\"that way,\" but she couldn't ignore the emotion, that surge of \n" +
"adrenaline that coursed through her body at the sight of Kimmie's\n" +
"wet, naked, voluptuous figure in the locker room showers.";
... Let's also create a textarea that has this same string, minus the "\n" characters:
继续阅读