-
-
Save jolij/a5458bda752ee4420c0d to your computer and use it in GitHub Desktop.
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(); |
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
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() { | |
$('p').click(function () { | |
SelectText('autoselect'); | |
}); | |
}); |
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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment