Reputation: 13
I have a text area. Where On enter it gives me the perfect line break. But When I render it in some templates it is not showing the line break. How can I rectify it? I don't want to use any jquery supported editor for that.
Upvotes: 1
Views: 4925
Reputation: 39808
((What the hell is a perfect line break?))
I'm guessing that you have a text-area who's text you're saving and then showing it in a div or p or span, and you want the line-breaks to actually show.
There are three ways:
<br />
element.white-space:pre;
style in CSS.<pre>
tag.Upvotes: 0
Reputation: 943099
The textarea gives you text, but presumably your templates are outputting HTML.
The text for a line break is \n
but the HTML for a line break is <br>
. You need to replace the former with the latter when converting between data formats.
(You also need to replace characters with special meaning in HTML (<
, >
, &
, '
and "
) with their entity counterparts to avoid XSS problems)
Upvotes: 1
Reputation: 122878
welcome to Stackoverflow (SO). Information on subjects like this is easy to find here. Check this SO question, or this one. Next time, try searching SO first.
Upvotes: 2