Skip to content

Instantly share code, notes, and snippets.

@zitterbewegung
Created September 28, 2014 16:54
Show Gist options
  • Select an option

  • Save zitterbewegung/6ba98f7a07cafeda524d to your computer and use it in GitHub Desktop.

Select an option

Save zitterbewegung/6ba98f7a07cafeda524d to your computer and use it in GitHub Desktop.
<script>
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);
}
}
document.onmouseover = function(e) {
if (e.target.className === 'click') {
SelectText('selectme');
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment