I have a prettily styled box for editing some raw text:
The box is a <div>
with contenteditable="true"
. I don't want to use textarea
because it's so damn annoying to style. Also, the <div>
has the wonderful property that it automatically scales to contain the text as the user types.
My problem with the div is that I can't seem to get the raw text out of it. When it's edited by the user, the browser inserts <div>
s and <br>
s to create line breaks, so when I fetch the text using innerHTML
I actually get a bunch of HTML rather than the raw text. If I use innerText
instead, it doesn't preserve any of the line breaks and I get this output:
"Foo bar: PowThis field is: AlignedWith: This fieldThree empty lines"
Are there any non-hack, non-workaround solutions provided by the browser to get the text out as it is displayed?
One interesting observation is that I can select the text and copy it into a text editor: