jQuery Removing specific text from an element

后端 未结 4 841
谎友^
谎友^ 2020-12-02 23:10

I want to remove the text \"By:\" from an element in my website. I want the rest of the text to remain there. How can I achieve that with jQuery? Thank you.

The HTML

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 23:59

    a more global solution using regular expressions. This will replace By: even if your string structure will change.

    var str = $('div').text().replace(/By:/g, '');
    $('div').text(str);
    
    
    By: Anonymous From Minnesota

提交回复
热议问题