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, '<') .replace(/>/g,'>') .replace(/\n/g, '<br/>');
Comments
Post a Comment