Possible Duplicate:
Replace all line break in a string with <br /> tag in javascript
How can I read the line break from a value with JavaScript and replace it with a <br />
tag?
Example:
var a = "This is man.
Man like dog."
I would like my result to look something like
var a = "This is man.<br />Man like dog.";
var newString=oldString.replace(/\n/g,"<br />");
To be complete: I've encountered cases where '\n' didn't work, in those cases I used:
someString.replace(/\n/g,'<br />')
.replace(/\r/g,'<br />')
.replace(/\r\n/g,'<br />');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With