Created
November 23, 2014 19:28
-
-
Save anonymous/eba2c2917c2b3696e91a to your computer and use it in GitHub Desktop.
// source http://jsbin.com/sidiwipupe
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
<script src="http://code.jquery.com/jquery-latest.js"></script> | |
<div> | |
<p>Some cool text!</p> | |
<br/> | |
<p>Some cool text!</p> | |
</div> | |
<div id="all-select"> | |
<p>Some cool text!</p> | |
<br/> | |
<p>Some cool text!</p> | |
</div> | |
<script id="jsbin-javascript"> | |
$.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(); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript"> $.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();</script> |
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
$.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