Find text string using jQuery?

后端 未结 7 1510
暖寄归人
暖寄归人 2020-11-22 07:38

Say a web page has a string such as \"I am a simple string\" that I want to find. How would I go about this using JQuery?

7条回答
  •  深忆病人
    2020-11-22 08:02

    If you just want the node closest to the text you're searching for, you could use this:

    $('*:contains("my text"):last');
    

    This will even work if your HTML looks like this:

    blah blah my text

    Using the above selector will find the tag, since that's the last tag which contains that entire string.

提交回复
热议问题