Slide 17
Slide 17 text
function getLegitTextNodes(el, f) {
var
blacklist = [‘SCRIPT’,‘OPTION’,‘TEXTAREA’],
filter = function (node) {
var parentName = node.parentElement.nodeName.toUpperCase();
if (blacklist.indexOf(parentName) >= 0) {
return NodeFilter.FILTER_REJECT;
}
if (!node.NodeValue.trim().length) {
return NodeFilter.FILTER_SKIP;
}
return NodeFilter.FILTER_ACCEPT;
},
walker = document.createTreeWalker(
el,
NodeFilter.SHOW_TEXT,
filter);
while(walker.nextNode()) f(walker.currentNode);
}
https://gist.github.com/mwunsch/4710561