<div id="div-editable" contenteditable>
<div style="cursor: text">this inner div is needed to make it work proper in IE</div>
</div>
<input style="margin-top: 10px" type="button" value="ParseDIVText" onclick="ParseDIVText()"/>
function ParseDIVText()
{
//NOTE: TYPE MORE TEXT WITH ENTER KEY IN THE EDITABLE DIV TO BETTER UNDERSTAND THIS PROBLEM.
//QUESTION: my solution is working in firefox and chrome but not in IE.
var domString = $("#div-editable").html();
domString = domString.replace(/<div style="cursor: text">/g, "<br>").replace(/<\/div>/g,"");
alert(domString);
//
//answer that was given by Laoujin at stackoverflow is not working....
var innerDOM = $("#div-editable").clone();
innerDOM.find("div[style='cursor: text']").unwrap().append("<br>");
alert(innerDOM.html());
//
//FINAL ANSWER
var domString = "", temp = "";
$("#div-editable div").each(function()
{
temp = $(this).html();
domString += "<br>" + ((temp == "<br>") ? "" : temp);
});
alert(domString);
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.