text-select - select text on any web web page

npm version Build Status

text-select is a tiny and helpful library to easily select text on web pages. Compared to other solutions, text-select can not only select text of HTML elements but you can also select a substring. text-select can also be used in end-to-end tests (e.g. using Protractor or TestCafe) to select any text during tests.

Features

Installation

Get started

import {selectElementText, selectText} from '@alidev/text-select/dist';
// Select the whole text of an element
selectElementText(document.getElementById('intro-header'));
// Select only a substring of an element's text
selectText(document.getElementById('contact-email', 'john.doe@ac.me'));
<script src="text-select.bundle.js"></script>

TextSelect.selectElementText(document.getElementById('intro-header'));

Compatibility

Examples

Local development setup

  1. Download the repository.
  2. Get Node.js and install it if you haven’t already.
  3. Use npm install to install the necessary dependencies.
  4. The source code is written in TypeScript in the src directory.
  5. Run npm run build to build the library.
  6. Run npm test to run the e2e tests.

Contribution

Pull requests and feature requests are welcome!