Multi-line textarea jQuery.append

I have a textarea which…

Login

Blog History

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:

success_one_line_newline

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

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

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 jquery.support test
function get_line_break() {

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

}

var line_break = get_line_break();

Success

 

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.