I need the ability to select an HTML range by providing it with an identifier selector. What I have below works fine in Chrome and Firefox, but not in IE 10 (standard mode). (older version of IE does not bother with this)
function selectElementContents(elementId) { var elemToSelect = document.getElementById(elementId); var selection= window.getSelection(); var rangeToSelect = document.createRange(); rangeToSelect.selectNodeContents(elemToSelect);
Demo : http://jsfiddle.net/7Jayc/
The strange part is that the string console.log(rangeToSelect) will correctly write the correct text in IE 10, but will not select it.
source share