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.
use
pretag , new lines respected.prepreformatted text , use non-proportional font may not render wish. see pre on mdn more details.replace new lines
brtag. can regular expression:stringvalue.replace(/\n/g, '<br/>'). more robust regular expression present on question: jquery convert line breaks br (nl2br equivalent).
Comments
Post a Comment