Search code examples
javascriptjqueryhtmlmultilinecarriage-return

How can I use jquery to display a multiline string text in a span?


I have to use jquery to take data and display it in a span that will have it show up on multiple lines?

var myString = "a\r\nb\r\nc\r\n";

and i want it to show up in my page / span as:

a
b
c

instead of:

a b c


Solution

  • Just do a replace

    myString = myString.replace(/\r\n/g,"<br />");