Highlight And Replace Text In JavaScript – HR.js

Category: Javascript , Recommended , Text | September 11, 2022
Author:mburakerman
Views Total:286 views
Official Page:Go to website
Last Update:September 11, 2022
License:MIT

Preview:

Highlight And Replace Text In JavaScript – HR.js

Description:

HR.js is a lightweight, Pure JavaScript library that enables you to highlight and replace specified character(s) within your text.

How to use it:

Download and insert the HR.js library into your html page.

<script src="src/hr.js"></script>

Create a new HR object and specify the target container in which text should be highlighted and replaced.

new HR(".container", {
    // options
})

Set the character(s) to highlight and replace with.

new HR(".container", {
    highlight: ["before1","before2"],
    replaceWith: ["after1","after2"]
})

Change the background color of the highlighted character(s).

new HR(".container", {
    highlight: ["before1","before2"],
    replaceWith: ["after1","after2"],
    backgroundColor: "#c4f5aa"
})

Changelog:

09/11/2022

  • v1.5.6

You Might Be Interested In:


Leave a Reply