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

后端 未结 5 1582
一生所求
一生所求 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 21:01

    If it's possible, you could wrap the word(s) you want to replace in a span tag, like so:

    This div contains some text.

    You can then easily change its contents with jQuery:

    $('.text_div > span').text('hello everyone');
    

    If you can't wrap it in a span tag, you could use regular expressions.

提交回复
热议问题