views:

205

answers:

3

I'm trying to create a very simple contentEditable div input. However, any way that I can think of to get the value of the input is not exactly what the user typed in IE because whitespace is collapsed. i.e. "hello world" becomes "hello world". But it's important to me that I be able to get the text as the user has typed it if at all possible. Any ideas how I can do this?

A: 

Did you try to read the innerHTML from the div?

Jonathan Weiß
Yes, it does not work.<html> <body> <div id="test">hello world</div> <script> alert(document.getElementById('test').innerHTML); </script> </body></html>
Ben McCann
A: 

It turns out that I can get the value just fine using innerHTML without IE collapsing any spaces. However, there is no way to set the value such that IE doesn't collapse spaces, which makes it absolutely impossible to unit test.

Ben McCann
A: 

Use the good old "&nbsp;" and it will work as you want ;)

john_doe