I am appending data to jQuery Accordion like this
$('<div>').append($('<p>').attr('style', 'font-size:10px').html(strData));
where my strData is a line coming from database. This string has line breaks,
but once it get appended, it loses all its line break and show in one line.
For the same data when in alert it, it shows as I want.
How is this caused and how can I solve it?
In HTML, linebreaks are represented by
<br>tags, not by CRLF characters.You need to either replace CRLF characters by
<br>tags, or to apply CSSwhite-space:preon the containing HTML element and usetext()instead ofhtml().Replacing CRLF by
<br>can be done at various ways. In the server side before returning thestrDatato JavaScript. For example, when you’re using Java:Or in the client side using JavaScript itself: