How do I get the value of a contenteditable
element?
Right now I just use innerHTML
to get the content of the element, which would result carriage returns as <br>
tags, so I need to convert <br>
tags to \n
right now.
Is there another more proper way to get the value from a contenteditable
element that I just don't know about?
Update:
In a textarea
element when you get the value e.g. textarea.value
the content is intact, like the carriage returns. Is there a similar way to get value from a contenteditable
element or I am forced to replace values?
content.innerHTML.replace(/<br\s*[\/]?>/gi, "\n")
element.textContent
only gets the text, carriage returns not included. So this does not solve my problem.
First paragraph
Second paragraph
`. – Tim Down Mar 18 '15 at 14:49