JSFiddle - React, Tailwind, and code Playground
HTML
<div id="div-editable" contenteditable>
<div style="cursor: text">https://stackoverflow.com/questions/3455931/extracting-text-from-a-contenteditable-div</div>
</div>
<input style="margin-top: 10px" type="button" value="ParseDIVText" onclick="parseDIVText();"/>
CSS
#div-editable
{
-moz-appearance: textfield-multiline;
font: medium -moz-fixed;
font: -webkit-small-control;
font-size: 13px;
overflow: hidden;
min-height: 200px;
width: 99%;
border: solid 1px #5E54EF;
}
#div-editable div
{
white-space: pre-wrap; /* CSS3 */
white-space: -moz-pre-wrap; /* Firefox */
white-space: -pre-wrap; /* Opera <7 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* IE */
}
JavaScript
function parseDIVText()
{ //FINAL ANSWER
var domString = "", temp = "";
$("#div-editable div").each(function(){
temp = $(this).html();
domString += "<br>" + ((temp == "<br>") ? "" : temp);
});
alert(domString);
}