Created
October 7, 2013 12:42
-
-
Save atishgoswami/6867251 to your computer and use it in GitHub Desktop.
javascript Select Text on click
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
| function SelectText(element) { | |
| var doc = document | |
| , text = doc.getElementById(element) | |
| , range, selection | |
| ; | |
| if (doc.body.createTextRange) { | |
| range = document.body.createTextRange(); | |
| range.moveToElementText(text); | |
| range.select(); | |
| } else if (window.getSelection) { | |
| selection = window.getSelection(); | |
| range = document.createRange(); | |
| range.selectNodeContents(text); | |
| selection.removeAllRanges(); | |
| selection.addRange(range); | |
| } | |
| } | |
| $(function() { | |
| $('#conf_detail').on( 'click', 'code', function(){ | |
| SelectText($(this).attr('id')); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment