• Stars
    star
    163
  • Rank 231,141 (Top 5 %)
  • Language
    HTML
  • License
    MIT License
  • Created almost 2 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Vanilla JS class to highlight search results in a textarea while maintaining the area's functionality

Text Highlighter

Vanilla JS class to highlight search results in a textarea while maintaining the area's functionality.

Check out the DEMO

Features

  • No dependencies
  • Can be used in as many textareas as needed, just instantiate for each one.
  • Responsive. The markings will adjust to screen size, textarea size and scroll.
  • Keeps the original background from the textarea
  • Can be properly destroyed. Will remove all events and structure.
  • Can choose between case sensitive and insensitive search.

Use this class if you need to highlight search results or any text in a textarea. Its use is very straightforward, instantiate the class for the textarea you need and call the search method to highlight the text you pass in the first argument. The second argument is optional and takes a boolean that if true will make the search case sensitive. The default is case insensitive.

Usage & Code Examples

Add the following files to your project:

  • texthighlighter.js
  • texthighlighter.css
let tarea = document.getElementById('txt');
let hilite = new textHighlight(tarea);

let searchResult = 'Some Expression';
let sens = true;                        // Optional
hilite.search(searchResult, sens);

Should you need to clear out the highlights, call the clear method.

hilite.clear();

When it falls out of scope, just call the destroy method and all will be as it was before instantiation.

hilite.destroy();

About

This class was inspired by lonekorean's highlight-within-textarea JQuery plugin. Basically, I needed a similar functionality for a project but didn't want to include JQuery just for that and didn't find any other such code.

This class was tested in Chrome 110 and Firefox 110.

Licence

This project is licensed under the MIT Licence

More Repositories

1

kineticsroll

Simple Vanilla JS module and Svelte action that transforms a container into a momentum scroller
JavaScript
12
star
2

ngCanvasGauge

Creates a semi circular gauge using HTML 5's canvas tag and Angular.js
HTML
9
star
3

ngPercentDisplay

Small Angular Directive to show a percent value inside a coloured circle representing the percentage
HTML
9
star
4

ngChoice

Dropdown or single menu in angular
HTML
6
star
5

svelte-maxchars

Svelte action to indicate the remaining space in textboxes or textareas
JavaScript
5
star
6

circularbar

Svelte component that emulates a circular percent based progress bar
Svelte
5
star
7

percentgauge

A Svelte component that creates a semi circular percent based gauge
Svelte
5
star
8

ngSimpleDatePick

A small angular date picker using JQuery and momentJS
JavaScript
4
star
9

idleness

Vanilla JS class to monitor the user's state of idleness
HTML
3
star
10

JSON-Translator

A CLI app able to translate a JSON file into any language automatically or manually.
JavaScript
3
star
11

ngTooltips

Angular directive to show tooltips on any element. Very easy to use and configure.
HTML
1
star
12

cidadesdobrasil

Lista de cidades do Brasil em formato JSON
1
star
13

pandacub-website

Svelte
1
star
14

ngSwitch

Tiny Angular Directive to create a switch button that changes from on to off, true to false, much like those found on mobile apps interfaces
HTML
1
star
15

svelte-keyactions

Simple Svelte action to enabled individual key events on any element.
JavaScript
1
star
16

textarearesizer

Vanilla JS class to make a textarea's height grow according to it's contents.
HTML
1
star