1

I came across this answer here as well as a few others on SO, that run a .createTextRange() method of a DOM element object. The closest reputable documentation to it that I could find was on Document.createRange() over at MDN, but that's definitely not it.

Could anyone explain this method? Such as what it returns? I would love to be pointed towards some documentation.

Cloud
  • 938
  • 1
  • 8
  • 24
  • 1
    According to [this answer](https://stackoverflow.com/a/41743191/774078), this method is a Microsoft specific answer, so it likely is not a good solution. It suggests using `createRange` which returns a Range object. – Sterling Archer Jan 31 '20 at 15:08

2 Answers2

2

I'm pretty sure createTextRange is an Internet Explorer specific method, which was used in IE v6, I believe.

I don't know which other versions of IE support it (maybe older versions, maybe newer versions), but it probably doesn't work in any other browser.

The old documentation that I was using year ago is gone, but I found this documentation about createTextRange:

(I'm used to MS changing their URLs, so I hope these links are not broken again)

I'm not sure anymore how to use it properly, and I can't test it, as I don't have an InternetExplorer, but here I took some lines from some of my old codes (I simplified it here, so I might have broken something):

var elm = document.getElementById("sourceText");
elm.value = 'some text';

const rng = elm.createTextRange();
rng.collapse( true );
rng.moveEnd( 'character', 7 );
rng.moveStart( 'character', 2 );
rng.select();
kca
  • 4,856
  • 1
  • 20
  • 41
-1

You entering the DOM .... the source to render it as a page and javacript

You get a range on selection events : selection, there is the current target then the selection... for à read it can help retrieve all selected elements in event data, after manipulating it ?...

At that level you will need the specification...

Ranges (are sub tree within the dom) It’s abstract definition show the tree of nodes address/structure appearing https://dom.spec.whatwg.org/#interface-abstractrange

And other related : https://dom.spec.whatwg.org/#ranges [DOM-Level-2-Traversal-Range] Joseph Kesselman; et al. Document Object Model (DOM) Level 2 Traversal and Range Specification. 13 November 2000. REC. URL: https://www.w3.org/TR/DOM-Level-2-Traversal-Range/

That’s it ?