Display line break in <div> tag from database Display line break in <div> tag from database database database

Display line break in <div> tag from database


if you want it to be exactly as it is in the database, then just render it inside a <pre> tag, instead of a <div>.

<pre id="tmpId">${f:h(dto.accPassage)}</pre>

That will preserve the exact formatting in the enclosed text block.


Since you're retrieving it from the DB, why do it client-side and not do the replace as soon as you retrieve the data from your DB ? Not sure what you're using (although that's irrelevant since this can be done in any language) but in PHP, assuming $output is your DB result it would be as easy as

$output = nl2br($output);

Hope this helps !


Use css to render /n correctly:

<span style="white-space: pre-line">Hi! next line, next line.</span>

in your case

<div id="tmpId" style="white-space: pre-line">${f:h(dto.accPassage)}</div>