Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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)
- Host: GitHub
- URL: https://github.com/nv/select-text.js
- Owner: NV
- Created: 2010-06-27T20:53:04.000Z (over 14 years ago)
- Default Branch: gh-pages
- Last Pushed: 2010-07-13T14:04:15.000Z (over 14 years ago)
- Last Synced: 2024-10-30T07:02:02.513Z (about 2 months ago)
- Language: JavaScript
- Homepage: http://nv.github.com/select-text.js/test/
- Size: 93.8 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.mdown
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.