Skip to content

Instantly share code, notes, and snippets.

@tessro
Created September 18, 2009 15:42
Show Gist options
  • Save tessro/189120 to your computer and use it in GitHub Desktop.
Save tessro/189120 to your computer and use it in GitHub Desktop.
A quick cross-browser jQuery plugin to select the contents of a node.
jQuery.fn.selectAll = function() {
return this.each(function() {
if (document.body.createTextRange) { // MSIE
var r = document.body.createTextRange();
r.moveToElementText(this);
r.select();
} else if (window.getSelection) { // W3C
var r = document.createRange();
r.selectNodeContents(this);
var s = window.getSelection();
s.removeAllRanges();
s.addRange(r);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment