How can I change an element's text without changing its child elements?

前端 未结 14 2340
难免孤独
难免孤独 2020-11-22 07:30

I\'d like to update element\'s text dynamically:

**text to change** text t
14条回答
  •  半阙折子戏
    2020-11-22 08:14

    **text to change**
    text that should not change
    text that should not change
    $(document).ready(function() {
        $("#divtochange").contents().filter(function() {
                return this.nodeType == 3;
            })
            .replaceWith("changed text");
    });
    

    This changes only the first textnode

提交回复
热议问题