javascript - Losing line break when displaying text -


i can see line breaks "↵" string in chrome developer tools

<br>↵↵<br>event status: confirmed↵<br>event description: hog day (night )and hog day (day)↵↵friday... 

if double click , paste notepad, line breaks preserved.

when save string object so,

var summary = el.find("summary").text(); var volunteerevent = {title: title, summary: summary} 

and display on page,

$('#volunteereventdescription').empty().html(event.summary); 

the line breaks gone , it's huge chunk of text.

how keep newlines?

i see 2 obvious options. 1 right 1 depends on how control on formatting want.

  1. use pre tag , new lines respected. pre preformatted text , use non-proportional font may not render wish. see pre on mdn more details.

  2. replace new lines br tag. can regular expression: stringvalue.replace(/\n/g, '<br/>'). more robust regular expression present on question: jquery convert line breaks br (nl2br equivalent).


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -