Get the selection as HTML using
public javascript v1 · immutablefunction getSelectionHTML(selection) { var range = (document.all ? selection.createRange() : selection.getRangeAt(selection.rangeCount - 1).cloneRange()); if (document.all) { return range.htmlText; } else { var clonedSelection = range.cloneContents(); var div = document.createElement('div'); div.appendChild(clonedSelection); return div.innerHTML; }}