Last active
September 29, 2015 02:32
-
-
Save masiuchi/58882635af858cf6e4ba to your computer and use it in GitHub Desktop.
Select text when clicking.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/questions/4165010/use-jquery-to-auto-select-text-inside-a-span-tag-when-clicked | |
(function($) { | |
$.fn.clickSelect = function() { | |
this.click(function() { | |
var range = document.createRange(); | |
range.setStartBefore(this.firstChild); | |
range.setEndAfter(this.lastChild); | |
var sel = window.getSelection(); | |
sel.removeAllRanges(); | |
sel.addRange(range); | |
}); | |
return (this); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment