I am working on a questionnaire application and one of the features is that the user can click on a question and and edit it. The problem I am having is converting a <br />
tag into a line break that my textarea will understand.
The save code looks as follows:
$('#questions').append("<div>"+$('textarea[name="question"]').val().replace(/\n/g, '<br />')+"</div");
This works perfectly! The code to convert it back looks like this:
$('textarea[name="question"]').val($('#questions').eq(1).html().replace(/<br\s*\/?>/mg,"\n"));
but for some reason the textarea will not accept the new lines and just bundles all of the text together.
How can I convert <br />
back into a new line feed that my textarea will understand?
Try
$('textarea[name="question"]').val($('#questions').eq(1).html().replace(/\s*<br\s*\/?>\s*/g,"\n"));
Demo: Fiddle
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