I m breaking a line in javascript using \n for example: -
text = "this is a test" + "\n" + "another test";
and to show that in html i m using the code
text = text.replace('\n' , '<br>');
but the text i m getting is without the br
when checking in firebug console i get is with line break(\n not shown but newline created)
how can i place line breaks using \n or i have to do some custom code instead of \n
thanks
I m breaking a line in javascript using \n for example: -
text = "this is a test" + "\n" + "another test";
and to show that in html i m using the code
text = text.replace('\n' , '<br>');
but the text i m getting is without the br
when checking in firebug console i get is with line break(\n not shown but newline created)
how can i place line breaks using \n or i have to do some custom code instead of \n
thanks
Share Improve this question edited Dec 29, 2010 at 21:31 Pratik 11.7k22 gold badges70 silver badges99 bronze badges asked Dec 29, 2010 at 21:28 Pradyut BhattacharyaPradyut Bhattacharya 5,74813 gold badges58 silver badges86 bronze badges 03 Answers
Reset to default 5var newText = text.replace(/\n/g , "<br>");
use double quotes to not escape the \n
try this:
text = text.replace("\n" , "<br>");
/\r\n|[\r\n]/g <- this is what I use. I am a pessimist..