SO jQuery Fiddle
Test Fiddle mainly for SO Questions jQuery 1.4.3, UI 1.8.5
by Nick Craver
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/themes/ui-lightness/jquery-ui.css">
<div id="edit" contentEditable="true"></div>
<button>Test</button>
CSS
#edit {
border: solid 1px #ddd;
width: 300px;
height: 200px;
white-space: pre;
}
JavaScript
$("button").click(function() {
alert($("#edit").getPreText());
});
$.fn.getPreText = function () {
var ce = $("<pre />").html(this.html());
if ($.browser.webkit)
ce.find("div").replaceWith(function() { return "\n" + this.innerHTML; });
if ($.browser.msie)
ce.find("p").replaceWith(function() { return this.innerHTML + "<br>"; });
if ($.browser.mozilla || $.browser.opera || $.browser.msie)
ce.find("br").replaceWith("\n");
return ce.text();
};