Skip to content

Instantly share code, notes, and snippets.

Created November 23, 2014 19:28
Show Gist options
  • Save anonymous/eba2c2917c2b3696e91a to your computer and use it in GitHub Desktop.
Save anonymous/eba2c2917c2b3696e91a to your computer and use it in GitHub Desktop.
<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>
$.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