3

Let's read a contenteditable element:

<span id="myinput" contenteditable="true">This is editable.<br>Yes it is.</span>

just after you added manually two white-spaces at the end of the text.

I get :

  • textContent => "This is editable.Yes it is. "

  • innerText => undefined

  • innerHTML => "This is editable.<br>Yes it is. &nbsp;"

  • jQuery .text() => same than textContent i.e. line breaks are lost

How to get "This is editable.\n Yes it is. "? (Of course some regex could work on innerHTML, but that's dirty : maybe there are lots of things that I should parse...)

Basj
  • 41,386
  • 99
  • 383
  • 673
  • If there's no simple way, it looks like a job for a _TreeWalker_ – Paul S. Sep 17 '14 at 14:30
  • I think there is no other way but using regex, there is are some nice answer here for the issue http://stackoverflow.com/questions/5959415/jquery-javascript-regex-replace-br-with-n – Teo Sep 17 '14 at 14:59

0 Answers0