Getting keywords to highlight

Have got the keywords to highlight. Is working using a javascript library called mark.js. Library was installed via node package manager.

Library is pretty simple to use. First we create an instance object like so:

var markInstance = new Mark(document.querySelector(“.context”));

where the context class is the div element we want to search for that instance. Then we can put the words that we want to highlight through the ‘mark’ method of the instance like so:


Currently I am storing the most popular words in an array called keywords, and looping thought this array and using the markInstance.mark() methods to highlight the words.

To get the array of keywords I had to stop the counter function from converting the keyowrds list to a string by removing the toString() method from the below line:

words.sort(function (a,b) { return frequencies[b] -frequencies[a];}).slice(0,cutOff).toString()

Now I will get a checkbox that highlights the words on check/uncheck.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s