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
Post a Comment