I can't get and replace line breaks in DIV element.
I need to get same form of text like it is in div
, but I must replace new lines with < br >
I have textarea and with jQuery I am copying text to < div id="text1">
, div has limited width ant text in div is automatically breaks to new line... and I need to get text from < div id="text1">
where the line breaks is replaced by < br>
HTML code:
<div id="text1" style="width:80px;">
Lorem ipsum dolor sit amet,
consectetuer adipiscing elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna
aliquam erat volutpat. Ut wisi enim ad minim veniam,
quis nostrud exerci tation ullamcorper suscipit
lobortis nisl ut aliquip ex ea commodo consequat.
</div>
jQuery code:
var result = $('text1').html();
result = result.replace(/\n/g,'<br>');
result = result.replace(/\r/g,'<br>');
Target OUTPUT:
Lorem ipsum dolor<br> sit amet,consectetuer <br> adipiscing....
The div has width 80px , so it automatically breaks the line.
Nothing of replace /r /n jQuery didn't work.
Thanks for any responses
` for actual linebreaks, or `white-space : nowrap` to get rid of them ? – adeneo Nov 07 '13 at 21:28
– user2899587 Nov 07 '13 at 21:30
– user2899587 Nov 07 '13 at 21:33