My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Links

A cross-browser JavaScript range and selection library. It provides a simple standards-based API for performing common DOM Range and Selection tasks in all major browsers, abstracting away the wildly different implementations of this functionality between Internet Explorer up to and including version 8 and DOM-compliant browsers.

For manipulating selections in <textarea> and <input type="text"> elements, see Rangy's poorly-named and svelter twin project, Rangyinputs.

Hosted files for the current stable release can always be found at http://rangy.googlecode.com/svn/trunk/currentrelease/. These are intended for use in demos using tools such as jsFiddle.


Download | Change log | Documentation | Demos | Discussion group

Contents


News

28 May 2012

Rangy 1.3 alpha released. The major new feature in 1.3 is the addition of the TextRange module.

26 February 2012

Rangy 1.2.3 released. This is a bugfix release that fixes  issue 84  and  issue 89 .

22 August 2011

Rangy 1.2 released. This release adds enhancements to the CSS class applier module and a few new core methods, plus several bugfixes.

New features and documentation


Uses

If you are a developing a JavaScript application that interacts with the user selection then Rangy will be able to help by providing a single API for all browsers and by simplifying common tasks.

A particularly common scenario is when dealing with editable content within the browser, using designMode or contentEditable.


Features

Rangy’s main features are:

  • Range and Selection wrappers for all browsers, including IE 6-8, providing a single familiar API;
  • Workarounds for several bugs in browser implementations of Range and Selection;
  • Mozilla Range extensions such as intersectsNode(), isPointInRange() and compareNode() available on all browsers;
  • Custom extensions to Range, including methods to iterate over all nodes within the Range and methods to split and normalize Range boundaries within text nodes;
  • A full JavaScript implementation of DOM Range.

Modules

Rangy also comes with modules, each of which builds on the core to provide a piece of user selection-related functionality. Current modules are:


Basic usage

var range = rangy.createRange();

// All DOM Range methods and properties supported
range.selectNodeContents(document.body);

// Selection object based on those in Mozilla, WebKit and Opera
var sel = rangy.getSelection();
sel.removeAllRanges();
sel.addRange(range);

Rangy also supplies convenience methods on its Range and Selection objects. For example, the previous two lines could be replaced by

sel.setSingleRange(range);

Browser support

Rangy is tested and works fully in the following browsers:

  • Internet Explorer 6 and later
  • Firefox 2.0 and later
  • Google Chrome 5.0 and later
  • Safari 3.2 and later
  • Opera 9.6 and later

Rangy may well work in many other browsers. It uses no specific browser detection, only feature detection, so any browser that has a minimal Range and Selection implementation will work to some degree. Also included are workarounds for some known flaws in older browsers such as Safari 2.

Powered by Google Project Hosting