Skip to content

Instantly share code, notes, and snippets.

@kaystrobach
Created October 28, 2014 14:08
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 kaystrobach/e8a0934da6f4ab82016a to your computer and use it in GitHub Desktop.
Save kaystrobach/e8a0934da6f4ab82016a to your computer and use it in GitHub Desktop.
jQuery: SelectElement: use $('#passwordVisible').selectElement();
$.fn.selectElement = function() {
var text = $(this).get(0);
var range = null;
if (document.body.createTextRange) { // ms
range = document.body.createTextRange();
range.moveToElementText(text);
range.select();
} else if (window.getSelection) { // moz, opera, webkit
var selection = window.getSelection();
range = document.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment