You want to operate on textnodes, and jQuery steers clear of textnodes. Since you can't wrap the text you want to change in a span or something like that, you can, with some effort, identify the textnodes and do some surgery. This is thrown together quickly, but seems to work:
/* utility function to help us skip whitespace-only nodes */
function isWhitespace( thenode ) {
return !(/[^\t\n\r ]/.test( thenode.data ));
}
/* attach this function to ready() or other trigger */
function fixtext(){
$('div#main')
.contents()
.filter( function() {
return !isWhitespace(this) && this.nodeType == 3;
// nodeType 3 means textNode. Force jQuery to ingest.
})
.each( function(){
$(this).replaceWith( document.createTextNode('Your new text') );
});
}
This can certainly be reduced and streamlined, but it seems to work using the information in your question, and should give you a starting point on the approach. It doesn't rely on matching your string exactly -- just that the string will be positioned in some larger container (I have it as div#main here), and it won't have any non-whitespace siblings. Even if your case is more complex, as long as the text is consistently placed you should be able to identify it within the filter() function.