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

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

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

**text to change** text t
14条回答
  •  悲&欢浪女
    2020-11-22 08:17

    Simple answer:

    $("div").contents().filter(function(){ 
      return this.nodeType == 3; 
    })[0].nodeValue = "The text you want to replace with"
    

提交回复
热议问题