jquery - How can i replace newline with <br> tag in JavaScript -


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

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -