If you only care about child nodes ...
$('#myDiv').contents().filter(function() {
return this.nodeType == 3
}).each(function() {
this.data = this.data.replace(/This is the semi-inner text/g, 'swapped');
});
jsFiddle .
If you want to check all descendant nodes, make the recurse function when it detects the node ( this.nodeType == 1) element .
alex source
share