jquery - How can i replace newline with <br> tag in JavaScript -
this question has answer here:
- how replace occurrences of string in javascript? 34 answers
- jquery javascript regex replace <br> \n 5 answers
in html code have 1 textarea. want change newlines <br>
tag , '<' 'lts'. how can jquery or javascript?
<textarea id='data'></textarea> <div id='result'></div>
how can replace enter
<br>
tag in javascript
you can use replace
var output = document.form1.mytextarea.value.replace("\n", "<br />"); // works first line break. var output = document.form1.mytextarea.value.replace(/\n/g, "<br />"); // need // added global variable str = str.replace(/(?:\r\n|\r|\n)/g, '<br />'); // replaces breaks in string.
add code in keyup
$('#data').keyup(function() { // code var text = $('#data').val(); var output = text.replace(/\n/g, "<br />"); }
Comments
Post a Comment