Multi-line textarea jQuery.append

Written by James McDonald

April 24, 2013

I have a textarea which I use jquery.append() to place error messages into.

$('textarea').append(status_text + line_break);

I have found that in Internet Explorer if I use a newline character “\n” for the line_break I get:


If I use a carriage return line feed “\r\n” in Internet Explorer I get a weird space inset.

If I use <br /> I get what I’m wanting which is each append on it’s own line.

I discovered inconsistent results in Firefox and Google Chrome but for all three a stable configuration was using browser feature detection to detect the htmSerialize (which incidentally tells us if it’s IE or a FF/GC) and then return the correct line break.

// set <br /> for i.e and \r\n for FF, GC
// ff and gc return true
// ie returns false for this test
function get_line_break() {

	return $.support.htmlSerialize ? "\r\n" : '<br />';


var line_break = get_line_break();




Submit a Comment

Your email address will not be published.

You May Also Like…

PHP Iterators

Just came across a Youtube talk "Iterators in PHP" by Jake Smith published in 2014 that steps through the many...

PHP array_map Multiple Arrays

array_map can take multiple arrays. I like how it starts mapping through them starting at the first element of each...