Quote Originally Posted by rnd me View Post
look no further:

Code:
function selHTML() {

    if (window.ActiveXObject) {
        var c = document.selection.createRange();
        return c.htmlText;
    }

    var nNd = document.createElement("p");
    var w = getSelection().getRangeAt(0);
    w.surroundContents(nNd);
    return nNd.innerHTML;
}
i noticed this wasn't working in chrome all the time; specifically if the range start and endpoints have different containers. there's a destructive version that works posted, but i thought i would share my harmless and fast update.
it also absolute-izes the hrefs and src, so your selected html will work anywhere it's pasted.

Code:
function selHTML() {

    if (window.ActiveXObject) {
        var c = document.selection.createRange();
        return c.htmlText;
    }
	var x=document.createElement("div"); 
	x.appendChild(getSelection().getRangeAt(0).cloneContents()); 
	[].slice.call(x.querySelectorAll("[src],[href]"))
		.forEach(function(a){a.href=a.href; a.src=a.src;;});
   return x.innerHTML;
}