Last active
August 29, 2015 14:14
-
-
Save andreruffert/7673c160dc490581c4ac to your computer and use it in GitHub Desktop.
Select all the content of an element. Supported in IE 9+
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
function selectContent(el) { | |
var range = document.createRange(); | |
var selection = window.getSelection(); | |
range.selectNodeContents(el); | |
selection.removeAllRanges(); | |
selection.addRange(range); | |
} | |
var el = document.getElementById("elementId"); | |
selectContent(el); |
deniztoprak
commented
Feb 6, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment