I have this html -:
<div id="myEditor" contenteditable="true"></div>
<textarea id="myArea"></textarea>
I have this jquery code -:
$("#myEditor").live("paste",function(){
var $this = $(this);
setTimeout(function(){ $("#myArea").val($this.text()); },2);
});
But when i use the above jquery code, all the line breaks and carriage returns are stripped off.
From Jquery documentation, I even tried using this , but in vain -:
$.valHooks.textarea = {
get: function( elem ) {
return elem.value.replace( /\r?\n/g, "\r\n" );
} };
But when I manually copy everything from div and paste it into textarea, line breaks are well preserved..
How do go about this issue. Thanks
Try this
$.valHooks.textarea = {
get: function( elem ) {
return elem.value.replace( /\r?\n/g, "<br />" );
} };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With