Replace word in

in

using jquery

前端 未结 8 1798
无人及你
无人及你 2021-01-18 11:54

I have a document with the following structure:

This is some text.

相关标签:
8条回答
  • 2021-01-18 12:53

    Try this, sure you will get your result.

    $("#notice p").text(function(i, text) {
        return text.replace("some", "My");
    });
    
    0 讨论(0)
  • 2021-01-18 12:55

    You need to target the p tag inside the #notice:

    $("#notice p").text(function(i, text) {
        return text.replace("some", "My");
    });
    

    Update 2020-03

    This same logic can now be made even simpler by using an arrow function:

    $('#notice p').text((i, t) => t.replace('some', 'My'));
    

    This will work in any browser except Internet Explorer.

    0 讨论(0)
提交回复
热议问题