You're probably using Internet Explorer than. Their developers implemented a TextRange object, which they often call simply a Range. However, the W3C DOM working group also created a Range object in DOM2. IE's TextRange object is not compliant at all with the DOM2 Range specifications, even though you sometimes see similarly named methods (createRange() for instace). That is probably what is confusing you.
Try using document.createRange() and the rest of your code in Mozilla. It will work fine.