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

gcc - MinGW's ld cannot perform PE operations on non PE output file -

How to connect android app to App engine -

hadoop - Running Map Reduce Job shows error - Mkdirs failed to create /var/folders/ -