Highlight a word with jQuery

后端 未结 12 1389
粉色の甜心
粉色の甜心 2020-11-22 01:20

I basically need to highlight a particular word in a block of text. For example, pretend I wanted to highlight the word "dolor" in this text:



        
12条回答
  •  青春惊慌失措
    2020-11-22 01:52

    You can use my highlight plugin jQuiteLight, that can also work with regular expressions.

    To install using npm type:

    npm install jquitelight --save
    

    To install using bower type:

    bower install jquitelight 
    

    Usage:

    // for strings
    $(".element").mark("query here");
    // for RegExp
    $(".element").mark(new RegExp(/query h[a-z]+/));
    

    More advanced usage here

提交回复
热议问题