jQuery Removing specific text from an element

后端 未结 4 843
谎友^
谎友^ 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:58

    var str = $("#text").text();
    $("#text").text(str.substring(3));
    
    
    By: Anonymous From Minnesota

    Using javascript's substring and give your div an ID to access it easily:

    html:

    By: Anonymous From Minnesota

    jquery:

    var str = $("#text").text();
    $("#text").text(str.substring(3));
    

    You could do it in one line too:

    $("#text").text($("#text").text().substring(3));
    

提交回复
热议问题