TheGuyWhoCodes TheGuyWhoCodes - 4 years ago 157
jQuery Question

mark.js Highlighting specific words

I have a monkey script to highlight parts of a site using mark.js with jquery. I have a value in the array called "New York". I would like it so when it finds the word "new" or "york" individually, it doesn't highlight it, just the string "new york"

var instance = new Mark(document.querySelector("body"));
instance.mark(["Total%20Loss%20Reported", "NY", "NJ", "stolen", "Canada", "frame%20damage", "moderate", "New%20Jersey", "New%20York", "structural", "accident", "damage", "damaged"], {
"accuracy": "exactly"
$('mark').css({'background':'transparent' , 'color':'red'});

Edit: I tried the %20 for spaces instead of a space, and it didn't work, also tried / /g

Answer Source

The documentation says to use separateWordSearch option:

instance.mark(["New York"], {
    accuracy: "exactly",
    separateWordSearch: false,
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download