i save data in a data base with json/jquery/ajax.
When i load the data in a textarea i get the result which i want to have.
But when i load the data in a DIV, then there are no line breaks.
I tested everything with css including
white-space:pre;
etc.
I’m saving the data in json with
"', 'text': '" + $('#textInput').val() +
but I’ve also tested it with .html() and .text().
Reading the data:
$('#textOutput').text(data.d.Text);
I’m getting the corect text in my div, but there are no line breaks!
CSS of textOutput
.textOutput // <div> not working, <textarea> working
{
width:100%;
border: 0;
height: auto;
overflow:visible; // also tested with auto etc.
margin: 5px 8px 5px 0px;
font-family: Courier New, Courier;
font-size: 12px;
// white-space:pre;
}
CSS of input is equivalent
If you are using PHP, you have to do a
nl2br()call to change the\n\rto a<br />tag. You can also do this in Javascript bydata.d.Text.replace(/\n/g, "<br />");For ASP you can use
.Replace("\n", "<br />").