Regex to find word on page including inside tags

后端 未结 4 631
-上瘾入骨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:11

    The only reliable way to accomplish this is to step through each child descendant and, if it's a text node, then run the replacement.

    Implementations:

    • http://benalman.com/projects/jquery-replacetext-plugin/
    • http://james.padolsey.com/javascript/find-and-replace-text-with-javascript/

    Doing it your way, not only do you run the risk of inadvertently replacing actual HTML, but you also wipe any DOM elements within the targeted element, and any corresponding event handlers.

提交回复
热议问题