replace newlines from a textarea to a div element - Javascript jQuery

Javascript examples for jQuery:Form Textarea

Description

replace newlines from a textarea to a div element

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-2.2.2.js"></script> 
  <script type="text/javascript">
    window.onload=function(){//from w  w w .j  a v  a  2s  .c  o m
str = $('textarea').val();
str = str.replace(/(?:\r\n|\r|\n)/g, '<br />');
$('#display').html(str);
    }

      </script> 
 </head> 
 <body> 
  <textarea>
Some test
no linebreaks
</textarea> 
  <br> 
  <div id="display"></div>  
 </body>
</html>

Related Tutorials