Sure, just write a recursive function to walk the DOM and filter text
nodes:
function traverseDOM(node) {
if (node.nodeType == 3 && node.parentNode.nodeName!='SCRIPT') {
//do something to the text content here
}
if (node.childNodes != null) {
for (var i=0; i < node.childNodes.length; i++) {
traverseDOM(node.childNodes.item(i));
}
}
}
traverseDOM($('body')[0]);
On Feb 19, 2:48 pm, David <[email protected]> wrote:
> I want to iterate over all text content in my document in order to
> replace certain text with other. It isn't safe for me to just work
> with the $().html() if the entire document because I might
> accidentally match and replace some of the non-textual content, eg
> values of attributes. I've been unable to use the obvious approach of
> filtering on nodeType=3 in order to get just the text nodes. I am not
> sure if it is related to this reported
> issue:http://www.nabble.com/Bug:-1.3_b1-selector--nodeType%3D3--not-working...
> Can anyone explain whether there is a way to accomplish what I want to
> do?
>
> Thanks
> David