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

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -