A more efficient JavaScript code for a highlighting function?

后端 未结 4 1393
Happy的楠姐
Happy的楠姐 2021-01-19 04:19

So this is the functionality I need to clean up:

I need to create a function where viewers can click on any word in a sentence, and it will be highlighted. However,

4条回答
  •  别那么骄傲
    2021-01-19 04:39

    A similar solution to Jorg's, with some variations. I've done the wrapping with split() and join() instead of regex. I also tend to put my jQuery chains on separate lines for visual clarity.

    
    
        
        
    
    
    
    
    

    Here is a sentence.

    Here is another sentence.

    Here is yet another sentence.

提交回复
热议问题