Created
September 18, 2009 15:42
-
-
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.
This file contains hidden or 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
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