Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
178
rated 0 times [  179] [ 1]  / answers: 1 / hits: 118429  / 14 Years ago, thu, may 27, 2010, 12:00:00

I'm having jQuery take some textarea content and insert it into an li.



I want it to visually retain the line breaks.



There must be a really simple way to do this...


More From » jquery

 Answers
8

demo: http://so.devilmaycode.it/jquery-convert-line-breaks-to-br-nl2br-equivalent




function nl2br (str, is_xhtml) {   
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
return (str + '').replace(/([^>rn]?)(rn|nr|r|n)/g, '$1'+ breakTag +'$2');
}





[#96673] Monday, May 24, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
longd

Total Points: 616
Total Questions: 110
Total Answers: 101

Location: Andorra
Member since Sat, May 27, 2023
1 Year ago
;