Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nv/select-text.js

Element.prototype.select(start, end) and Text.prototype.select(start, end)
https://github.com/nv/select-text.js

Last synced: 5 days ago
JSON representation

Element.prototype.select(start, end) and Text.prototype.select(start, end)

Awesome Lists containing this project

README

        

# select-text.js
Makes text selection a little less horrible. It's about [Selection](https://developer.mozilla.org/en/DOM/Selection) and [Ranges](http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html).

## Example


I'm Zaphod Beeblebrox, my father was Zaphod Beeblebrox the Second...

Let's say we want to set a selection to "Beeblebrox the Second.":


var quote = document.getElementById("quote")
var string = "Beeblebrox the Second."
var startIndex = quote.textContent.indexOf(string)
quote.select(startIndex, startIndex + string.length)

How would you do that without `select` method?

## [Tests](http://nv.github.com/select-text.js/test/)
Works well in Google Chrome 6.0.447.0, Safari 5.0, and Opera 10.54. A little buggy in Firefox 3.6.6.