selection.addrange() deprecated
selection = window.getSelection(); // Save the selection.
range = document.createRange();
range.selectNodeContents(elem);
selection.removeAllRanges(); // Remove all ranges from the selection.
selection.addRange(range); // Add the new range.