mark.js Highlighting specific words

谁说我不能喝 提交于 2020-05-28 03:36:33

问题


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" Code:

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


回答1:


The documentation says to use separateWordSearch option:

instance.mark(["New York"], {
    accuracy: "exactly",
    separateWordSearch: false,
});



回答2:


You have to disable the option separateWordSearch. Set it to false and it will highlight only "new york" and not single words of it. Btw.: Don't use "%20" for spaces.

Have a look at the documentation for more information.



来源:https://stackoverflow.com/questions/38622653/mark-js-highlighting-specific-words

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!