[removed] replace() all but only outside html tags

后端 未结 2 1589
南方客
南方客 2020-12-21 07:18

I have an autocomplete form and when showing the results matching the user\'s search string, I want to highlight the search string itself. I plan to do this by wrapping any

2条回答
  •  渐次进展
    2020-12-21 07:50

    Parse the HTML and find all text nodes in it, doing the replace in all of them. If you are using jQuery you can do this by just passing the snippet to $() which parses it in a Document Fragment, which you can then query or step over all elements and find all the .text() to replace.

提交回复
热议问题