jquery - Copy a textarea value into a div keeping line breaks and html as text -


i working on trying way whatever in textarea move on div on button click. of key features looking want linebreaks stay , if user inputs kind of html tags, cross on shown same way.

so entered:

<body>     <p>blah blah blah</p>     <p>more text</p> </body> 

will still same in div area.

i have tried couple of things, have tried this:

var value = $('#selector-input textarea').val().replace(/\n/g, '<br/>'); $('#selector-canvas #canvas').text(value); 

does have ideas? appreciated. thanks!

if want preserve tags have replace angle brackets first, followed replacing newline characters - http://jsfiddle.net/jayblanchard/2kg9f/

var value = $('textarea').val()     .replace(/</g, '&lt;')     .replace(/>/g,'&gt;')     .replace(/\n/g, '<br/>'); 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -