Regex to find word on page including inside tags

后端 未结 4 637
-上瘾入骨i
-上瘾入骨i 2021-01-28 15:13

Thanks to Chetan Sastry I have this Regex code to parse my page for a list of words and add the TM to them.

var wordList = [\"jQuery UI\", \"jQuery\", \"is\"];
v         


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-01-28 16:10

    J-P linked to some good utilities for the job.

    With straight jQuery:

    $elem
      .contents()
      .filter(function() {
        return this.nodeType == Node.TEXT_NODE;
      })
      .each(function(){
        $(this).text($(this).text().replace(regExp, "$&™"));
      });
    

    (SEE How do I select text nodes with jQuery?)

提交回复
热议问题