How to change only text node in element

前端 未结 8 831
不知归路
不知归路 2020-11-28 10:40

I have next html:


And I want to chang

8条回答
  •  生来不讨喜
    2020-11-28 10:54

    If you use contents() method it will also return text nodes. Since jQuery doesn't have text node methods, convert last node to a DOM node

    $('label[for="user_name"]').contents().last()[0].textContent='Title';
    

    Demo: http://jsfiddle.net/yPAST/1/

提交回复
热议问题