Highlight And Replace Text In JavaScript – HR.js

Category: Javascript , Recommended , Text | April 23, 2017
Author: mburakerman
Views Total: 1,589
Official Page: Go to website
Last Update: April 23, 2017
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"
})

You Might Be Interested In:


Leave a Reply