Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/mburakerman/hrjs

🔄 Tiny JavaScript plugin for highlighting and replacing text in the DOM
https://github.com/mburakerman/hrjs

dom highlight highlight-text javascript replace-text

Last synced: 3 months ago
JSON representation

🔄 Tiny JavaScript plugin for highlighting and replacing text in the DOM

Awesome Lists containing this project

README

        

# HR.js

> Tiny JavaScript plugin for highlighting and replacing text in the DOM


[![NPM](https://img.shields.io/npm/v/hrjs)](https://www.npmjs.com/package/hrjs)
![NPM License](https://img.shields.io/npm/l/hrjs)


## âŦ Install

```js
npm install hrjs
```

or use CDN:
```html

```

## đŸĒĄ Usage

```html

Lorem ipsum dolor sit amet.


```

```html

new HR("#mytext", {
highlight: "dolor",
replaceWith: "cat",
backgroundColor: "#B4FFEB"
}).hr();

```
That's it!

[CodePen demo](https://codepen.io/anon/pen/ZKWBYV)

![CodePen demo](https://media.giphy.com/media/l4FGuX1VuJFbENUjK/giphy.gif)

### đŸĒĄ Multiple Keywords example

You can also highlight and replace multiple keywords.

```html

I love JavaScript.


```

```html

new HR("#mytext", {
highlight: ["love","JavaScript"],
replaceWith: ["like", "jQuery"],
backgroundColor: "#B4FFEB"
}).hr();

```
[CodePen Multiple demo](https://codepen.io/anon/pen/XRdNbw)

### đŸĒĄ Highlight example

To highlight only, just add your keyword to `highlight` option.

```html

Lorem ipsum dolor sit consectetur amet.


Consectetur enim ipsam voluptatem quia


```

```html

new HR(".mytext", {
highlight: "consectetur",
backgroundColor: "#B4FFEB"
}).hr();

```
[CodePen Highlight demo](https://codepen.io/anon/pen/Vbampm)

## ✅ Test
Clone project, install dependencies and run `npm run test`

## ⚙ī¸ Customize

These are default options.

```js
new HR("elem", {
highlight: null,
replaceWith: null,
backgroundColor: "#FFDE70"
}).hr();
```

## Šī¸ License

Licensed under the MIT License.