Skip to content

Instantly share code, notes, and snippets.

@jeffisabelle
Created October 21, 2014 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffisabelle/15d5b0ef671a8d34a32b to your computer and use it in GitHub Desktop.
Save jeffisabelle/15d5b0ef671a8d34a32b to your computer and use it in GitHub Desktop.
highlight selected
function highlightSelected() {
var sel = window.getSelection();
var div = document.createElement("div");
div.className = "highlighted";
if (sel.rangeCount) {
var range = sel.getRangeAt(0).cloneRange();
try {
range.surroundContents(div);
} catch(err) {
alert("multiple tag highlighting not supported. (yet)");
}
sel.removeAllRanges();
sel.addRange(range);
}
$('.highlighted').click(function() {
var html = $(this).html()
$(this).after(html);
$(this).remove();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment