Preserve newlines when setting html in a div from a textarea - Jquery -


i got little html -:

<div id="viewone"></div> <textarea id="viewtwo"></textarea> <button id="copytodiv" value="copy div"></button> 

this jquery snippet-:

$("#copytodiv").on("click",function(){ $("#viewone").html( $("#viewtwo").val() ) }); 

but strips of new line characters textarea's val , string new lines stripped off. how preserve newlines when setting html of div. lot :)

the new lines preserved, not converted html new lines (<br/>), ignored.

you can convert them <br/> .replace:

$("#copytodiv").on("click",function(){ $("#viewone").html( $("#viewtwo").val().replace("\n","<br/>") ) }); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -