A javascript selection script

I wanted a lightweight and cross browser plugin to be able to handle selections in a text area (for my griffin.editor plugin). Didn’t find a suitable one despite asking at stackoverflow.com. I created my own. It’s stand alone and only 2,6kb (uncompressed).


//jQuery is not required but supported.
var selection = new TextSelector($(‘#mytextarea’));
selection.replace(‘New text’);

// you can change selection:
selection.select(1,10); // select char 1 to 10

// get selection information
console.log("Start char: " + selection.get().start);

// check if anything is selected

// get the text
var text = selection.text();

Code at github