I have to display an article from database inside a < div> tag. This article was inserted into database from a textarea. My problem is: i could not display exactly the structure that i inserted from the textarea (including line break)
I tried the below code to replace the enter character to < br> tag but it did not work
<div id="tmpId">${f:h(dto.accPassage)}</div>
<script>
$(function(){
$('#tmpId').html($('#tmpId').html().replace(/\n/g, '<br />'));
})
</script>
I wonder if someone could give me some hints to solve this problem.
Thank you very much.
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.
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