To get to the textnodes within an element you need to use contents()
and then filter()
by nodeType. You can then use replaceWith()
to change the text. Try this:
$('li:first b').contents().filter(function() {
return this.nodeType == 3;
}).replaceWith('foo');
I obviously hard-coded this to use the first li
element, but you can change the selector as needed.