Gary Ryan Gary Ryan - 1 month ago 7
Ajax Question

Line breaks won't display in textarea in IE

Using jQuery's

.load()
method I'm loading text into a textarea. Works fine in Chrome & FF. As always, IE just has to be different and won't display the line breaks.

I've tried
white-space:pre-wrap
with no luck.

Any ideas?

My code:

$('#textarea').load('data.php');


The data.php simply queries a MySql database and prints the results.

Answer Source

They're compatibility problems with IE when using innerHTML(). As Jquery's .html() and .load() methods both use innerHTML(), they by extension can result in some issues. One solution is to use .text() instead. If you want to load text into a <textarea> using AJAX and Jquery you need to do something like this:

$('#textarea').post('data.php',function(data){
        $(this).text(data);
    })
);