I have got a button 'edit description' when I click on it text disappear and appear
if (id == 'commedit') jQuery(this).html('<textarea>'+jQuery(this).text()+'</textarea>');
else if (id == 'commsave') {
jQuery(this).text(jQuery(this).find('textarea').val());
}
In MySql I have this text - "tetee<br>afafaf<br>afafaf<br>afsafsasfasf"
in view it dispays with line breaks but when I click 'edit' in text area which come with Jquery text appear without lines and when I click save it also appear in my description field in one long line without line breaks. So I need your help
<br>
are html breaks. You want \n
in a textarea.
jQuery(this).html().replace(/<br>/gi,"\n")
When you save, you want to change it back to breaks and use html() instead of text();
var elem = jQuery(this);
if (id === 'commedit') {
var text = jQuery(this).html().replace(/<br>/gi,"\n");
elem.html('<textarea>'+ text +'</textarea>');
} else if (id === 'commsave') {
var html = elem.find('textarea').val().replace(/\n/g,"<br>");
elem.html(html);
}
JSFiddle Example
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