The .val() property of an item in jQuery for a doesn\'t seem to work with new lines. I need this function as the text-area is mean
Your newlines output perfectly, but HTML ignores newlines: it needs .
Use a simple newline-to-br function like so:
function nl2br_js(myString) {
var regX = /\n/gi ;
s = new String(myString);
s = s.replace(regX, "
\n");
return s;
}
$( "#watched_textarea" ).keyup( function() {
$( "#output_div" ).html( nl2br_js($( this ).val()) );
});
jsfiddle here: http://jsfiddle.net/r5KPe/
Code from here: http://bytes.com/topic/javascript/answers/150396-replace-all-newlines-br-tags