How to change only text node in element [duplicate]

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/

Leave a Comment