Skip to content

Instantly share code, notes, and snippets.

@danwarfel
Last active April 10, 2017 08:46
Show Gist options
  • Save danwarfel/624d375447297c80343c to your computer and use it in GitHub Desktop.
Save danwarfel/624d375447297c80343c to your computer and use it in GitHub Desktop.
JavaScript: Clear Selection
function clearSelection() {
if (window.getSelection) {
var selection = window.getSelection();
if (selection.removeAllRanges) {
selection.removeAllRanges();
} else if (selection.empty) {
selection.empty();
}
} else if (document.selection) {
document.selection.empty();
}
}
// from http://codesr.thewebflash.com/2015/10/javascript-clear-selection.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment