Get plain text from a content div

Is it possible to extract plain text from a contenteditable div, including newlines? The jQuery $ .text () method removes the new lines that I need. The solution may use jQuery.

+5
source share
3 answers

With a bit of tweaking, https://github.com/vorushin/jsHtmlToText was exactly what I needed.

+6
source

innerText textContent ( ). textContent , IE 6-8, innerText.

var text = x.innerText || x.textContent

http://www.quirksmode.org/dom/w3c_html.html#t07

EDIT: AgentME, Firefox. contenteditable, polyfill innerText Firefox. , :

  • x.innerHTML, / <br> &nbsp; \n .
  • Firefox Selection Range. Firefox Selection.toString, innerText, . , , , , contenteditable div, Selection.toString, .

, ; , HTML- CSS. 2 , , , onchange - . 2 .

:

+5

, - . innerText , ( ) . toString() , , . , : DOM <br> . , , - , , -, , HTML.

: Rangy .

0

All Articles