I have a string say
string display_txt = "1st line text" +"\n" + "2nd line text";
in Jquery, I am trying to use
('#somediv').html(display_txt).css("color", "green")
quite clearly I am expecting my msg to be displayed in 2 lines, but instead \n is being displayed in the message. Any quick fixes for that?
Thanks,
To add a line break to your HTML code, you use the <br> tag. The <br> tag does not have an end tag. You can also add additional lines between paragraphs by using the <br> tags. Each <br> tag you enter creates another blank line.
The \n character matches newline characters.
In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF. Adding a new line in Java is as simple as including “\n” , “\r”, or “\r\n” at the end of our string.
HTML Line Breaks The HTML <br> element defines a line break.
Set your css in the table cell to
white-space:pre-wrap;
document.body.innerHTML = 'First line\nSecond line\nThird line';
body{ white-space:pre-wrap; }
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