Can anyone suggest a plugin which can handle text selections in text areas (cross browser)?
I’m looking for a plugin which can:
- Get current selection
- Replace current selection
- Select a range
(IE uses createTextRange while other browsers use setSelectionRange. There ought to exist an plugin which can do the above so that I don’t have to reinvent the wheel.)
jQuery Fieldselection:
https://github.com/localhost/jquery-fieldselection
See:
https://github.com/localhost/jquery-fieldselection/blob/master/jquery-fieldselection.js
Implements: getSelection, replaceSelection
Does not implement: currentSelection
Rangy:
Implements: getSelection, ReplaceSelection, CurrentSelection
(note: not a jquery plugin, but widely applicable still)
Seems to implement what you want, for demo’s see:
http://rangy.googlecode.com/svn/trunk/demos/core.html
http://code.google.com/p/rangy/
See also: Jquery: selectionStart for non textarea elements
Rangyinputs
A jquery plugin that offers similar functionality as Rangy, except for inputs instead of arbitrairy DOM elements.
Demo: http://rangyinputs.googlecode.com/svn/trunk/demos/textinputs_jquery.html
Project: http://code.google.com/p/rangyinputs/