fbas
fbas

Reputation: 1674

IE - how to preserve white space in textarea, inputting with javascript string

FF and Chrome are behaving nicely, but IE (8) is not keeping the white space in my formatted code I'm putting into a TEXTAREA

<textarea id="vdt_table_textarea" style="white-space: pre"></textarea>

and

var vdt_demo_table_string = '&lt;table id=&quot;example&quot; class=&quot;display&quot;&gt;\n\
  &lt;thead&gt;\n\
    &lt;tr&gt;\n\
      &lt;th&gt;Rendering engine&lt;/th&gt;\n\
      &lt;th&gt;Browser&lt;/th&gt;\n\
      &lt;th&gt;Platform(s)&lt;/th&gt;\n\
      &lt;th&gt;Engine version&lt;/th&gt;\n\
      &lt;th&gt;CSS grade&lt;/th&gt;\n\
    &lt;/tr&gt;\n\
  &lt;/thead&gt;\n\
  etc....
';

$(document).ready(function() {
  $('#vdt_table_textarea').html(vdt_demo_table_string.replace(' ', '&nbsp;'));
});

how can I make IE respect my authoritah?!

Upvotes: 4

Views: 6612

Answers (3)

Zia ul Qamar
Zia ul Qamar

Reputation: 33

Define your and your close tag </ textarea> in same line.

Upvotes: 1

James Montagne
James Montagne

Reputation: 78690

Not sure why your way doesn't work, but this does:

$('#vdt_table_textarea').html(vdt_demo_table_string.replace(/ /g, '&nbsp;'));

Upvotes: 2

avetarman
avetarman

Reputation: 1252

CSS

textarea{
white-space:pre;
}

Or

textarea{
white-space:pre-wrap;
}

Upvotes: 7

Related Questions