jQuery if div contains this text, replace that part of the text

后端 未结 5 1581
一生所求
一生所求 2020-11-29 20:05

Like the title says, I want to replace a specific part of the text in a div.

The structure looks like this:

This d
5条回答
  •  半阙折子戏
    2020-11-29 20:48

    You can use the contains selector to search for elements containing a specific text

    var elem = $('div.text_div:contains("This div contains some text")')​;
    elem.text(elem.text().replace("contains", "Hello everyone"));
    

    ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

提交回复
热议问题