I've been working with selection/range objects, and because to the incredible amount of inconsistencies between browsers for specific selection/range stuff (even more than the DOM) I was wondering if there was a framework that would help me get through them.
Asked
Active
Viewed 6,586 times
12
-
Have you seen http://code.google.com/p/ierange/ ? – Roatin Marth Jan 25 '10 at 19:11
-
Roatin, this is exactly what i was looking for! Can you make it a question so I can upvote you? :) – Luca Matteis Jan 25 '10 at 19:52
3 Answers
13
I've written a new range/selection library called Rangy that is similar in concept to IERange but goes quite a lot further. The core is pretty much complete and currently available to download. I'm currently bugfixing and documenting it and it should be only be a few weeks before a full release.
UPDATE 31 August 2011
Rangy is now stable and at version 1.2 (downloads page).

Tim Down
- 318,141
- 75
- 454
- 536
-
Thanks for your great work on Rangy Tim Down. I'm using your lib in my new project and already have send you a bug report. I think it would be a good idea to create a mailing list, so that it is possible to discuss issues/features and suggest new features (maybe with a patch). Eg., I'm currently trying to get a startOffset and endOffset for the commonAncestorContainer rather than start/end containers. This would be a helpful feature I believe. – Tom Oct 19 '10 at 10:04
8
(Made an answer by request ;)
Take a look at IERange:
IERange is a feature-complete implementation of W3C DOM Ranges for Internet Explorer, allowing users to write one cross-browser version of their range manipulation code.
Supports Range APIs:
document.createRange()
startContainer
,startOffset
,endContainer
,endOffset
,commonAncestorContainer
,collapsed
setStart()
,setEnd()
,setStartBefore()
,setStartAfter()
,setEndBefore()
,setEndAfter()
,selectNode()
,selectNodeContents()
,collapse()
insertNode()
,surroundContents()
extractContents()
,cloneContents()
,deleteContents()
compareBoundaryPoints()
,cloneRange()
,createContextualFragment()
,toString()
Supports Selection APIs:
- Range support (Webkit-style)
window.getSelection()
addRange()
,removeAllRanges()
,getRangeAt()
,toString()

Roatin Marth
- 23,589
- 3
- 51
- 55
-
1IERange's biggest strength is its algorithms for expressing a `TextRange` in terms of nodes and offsets (as a Range does) and converting such and object back into a `TextRange`. However, it cannot fully abstract away the differences between the two: for example, the underlying `TextRange` will change in response to changes in the DOM while the `IERange` built upon it will not reflect these changes. There are also discrepancies between how the user selection is represented as a Range, which are down to the browser. [continued] – Tim Down Jan 26 '10 at 10:42
-
1Also note that creating an `IERange` is hugely slower than getting a DOM Range in other browsers. None of these are the library's fault; it's simply the nature of the problem. In short, best use with care and knowledge of the abstraction `IERange` represents. – Tim Down Jan 26 '10 at 10:44
1
fieldselection is a very usable jquery plugin for selection/range manipulation.

miku
- 181,842
- 47
- 306
- 310