How to only change the text in a DOM element without replacing any child elements

前端 未结 7 1248
一个人的身影
一个人的身影 2021-01-17 17:58

Hi I have a simple html structure

Title text inner text

What I want is to replace only the te

相关标签:
7条回答
  • 2021-01-17 18:41

    Another short jQuery solution:

    $("h1").contents().first().replaceWith("new text");
    

    DEMO: http://jsfiddle.net/FvbJa/1/

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