4

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?!

3 Answers 3

7

CSS

textarea{
white-space:pre;
}

Or

textarea{
white-space:pre-wrap;
}
Sign up to request clarification or add additional context in comments.

Comments

2

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

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

3 Comments

excellent. thanks. points to you. I decided to go another route and just use tinymce for the source as well as allow visual editing of the table.
I believe you will find that the string.replace only replaces the first occurrance when doing string replacement.
@RogerWillcocks that's what the g at the end is for, stands for global I believe.
1

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

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.