Skip to content

Instantly share code, notes, and snippets.

@atishgoswami
Created October 7, 2013 12:42
Show Gist options
  • Select an option

  • Save atishgoswami/6867251 to your computer and use it in GitHub Desktop.

Select an option

Save atishgoswami/6867251 to your computer and use it in GitHub Desktop.
javascript Select Text on click
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