To get text from child text nodes, you can do this:
var text = $('selector').contents().map(function() { // If it is a textNode, return its nodeValue if(this.nodeType == 3) return this.nodeValue; }).get().join('');ββββββ
I donβt know exactly what you want to do with the text, but if you want to process it when you go and replace it with the new text / html, you should do .each() instead and use .replaceWith() .
$('selector').contents().each(function() { if(this.nodeType == 3) {
Here is an example: http://jsfiddle.net/ZNjCW/
source share