Created
August 19, 2021 23:19
-
-
Save iacchus/a8049a9539303626fac1074c24c64d3c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// see it here: | |
// https://stackoverflow.com/questions/7563169/detect-which-word-has-been-clicked-on-within-a-text | |
// https://jsbin.com/oXetAcI/4/edit?html,js,output | |
$.fn.OneClickSelect = function(){ | |
return $(this).on('click',function(){ | |
var range, selection; | |
if (window.getSelection) { | |
selection = window.getSelection(); | |
range = document.createRange(); | |
range.selectNodeContents(this); | |
selection.removeAllRanges(); | |
selection.addRange(range); | |
} else if (document.body.createTextRange) { | |
range = document.body.createTextRange(); | |
range.moveToElementText(this); | |
range.select(); | |
} | |
}); | |
}; | |
// Apply to these elements | |
$('p, #all-select').OneClickSelect(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/questions/7563169/detect-which-word-has-been-clicked-on-within-a-text