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/


Sorry for the late reply... But here is a way to do so using only jQuery:

$('label').contents().last().replaceWith('Title');

It may not be the prettiest way, but this works:

var $label = $('label[for=user_name]');
$label.html($label.html().replace("Name", "Title"));