bboks.net™

New Line in Textarea to be converted to <br/> 본문

Web/jQuery

New Line in Textarea to be converted to <br/>

bboks.net 2014. 5. 28. 17:32

This will replace line breaks to HTML break tags. The different combinations are to cover the different browsers/systems and how line breaks are interpreted.


$(this).val().replace(/\r\n|\r|\n/g,"<br />")

This will bring it back to new lines - also covering how different browsers interpret innerHTML.


boxText.replace(/<br\s?\/?>/g,"\n");


[출처] New Line in Textarea to be converted to <br/>