The Code
Tested in Chrome:
function getSelectionHtml(selection) { var range = selection.getRangeAt(0); var div = document.createElement('div'); div.appendChild(range.cloneContents()); var htmlText = div.innerHTML; return htmlText; } function parseSelection() { var selection = window.getSelection(); if(selection.rangeCount > 0) { var selectedHtml = getSelectionHtml(selection); console.log("selectedHtml: " + selectedHtml); } } parseSelection();