Skip to content

Instantly share code, notes, and snippets.

@antiops
Created July 5, 2020 15:50
Show Gist options
  • Save antiops/37f1e66a77fcf4ad29a71cab8506da0a to your computer and use it in GitHub Desktop.
Save antiops/37f1e66a77fcf4ad29a71cab8506da0a to your computer and use it in GitHub Desktop.
// onclick="select_all(this)"
function select_all(el) {
if (typeof window.getSelection != "undefined" && typeof document.createRange != "undefined") {
var range = document.createRange();
range.selectNodeContents(el);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
} else if (typeof document.selection != "undefined" && typeof document.body.createTextRange != "undefined") {
var textRange = document.body.createTextRange();
textRange.moveToElementText(el);
textRange.select();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment