I'm switching formatted text (programming code) between a pre and a text area, programmatically using jQuery. Since I'm using a syntax highlighter on the pre, I'm also putting a copy of the code in an invisible div to use it as a temporary store before moving the code back undistorted to the textarea.

Code:

<pre> </pre>
<textarea> </textarea>
<div style="display:none"></div>

It works beautifully everywhere except on any version of IE. Transferring the text out of the div (using .html() on jQuery) removes all sorts of formatting from IE. Any ideas or workarounds you know about are appreciated.

I feel that some sort of escaping is involved but don't know how or why.

Cheers!

09-24-2009, 06:33 AM

method8

Format problems under IE divs and textarea

I wrote this small piece of code to show you better what I mean. Try putting in text with spaces etc, in your code in IE and other browsers. It keeps the formatting (spaces and tabs etc) in Firefox but not in IE.

I finally managed to sort it. It was in fact related to escaping. Escaping the code before and unescaping afterwards helps solve the problem across the browsers including Internet Explorer. Here's the corrected version of my example snippet