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

前端 未结 7 1307
一个人的身影
一个人的身影 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条回答
  •  旧时难觅i
    2021-01-17 18:32

    Using jQuery.contents() you can replace the nodeValue similar to this:

    $("h1").contents()[0].nodeValue = "new text ";
    

    DEMO using jQuery.contents() to replace a text node


提交回复
热议问题