javascript - how to get properly formatted text value from a div -
i trying formatted text contenteditable='true' div send server.
i used use textarea , when value of textarea preserves white space , line breaks, when using contenteditable div when using styles such following can not formatted text:
white-space: pre-wrap; word-wrap: break-word;
for example if type div:
"a aa asdf"
i out textcontent:
"a aaasdf"
is there way formatted text out of contenteditable div textarea?
use .innerhtml
linebreaks too.
readup: .innerhtml
| mdn
working code snippet:
document.getelementbyid('copy').addeventlistener('click', function(){ var text = document.getelementbyid('input').innerhtml; document.getelementbyid('output').innerhtml = text; });
div{ width: 200px; height: 200px; border: 1px solid black; display: inline-block; vertical-align: top; }
<div contenteditable='true' id="input">enter funny<br>;)</div> <button id="copy">copy text</button> <div id="output">text copied here.</div>
Comments
Post a Comment