getTextNodes
$.fn.getTextNodes = function (includeWhitespaceNodes) {
var textNodes = [], nonWhitespaceMatcher = /\S/;
function _getTextNodes(node) {
if (node.nodeType == 3) {
if (includeWhitespaceNodes || nonWhitespaceMatcher.test(node.nodeValue)) {
textNodes.push(node);
}
} else {
for (var i = 0, len = node.childNodes.length; i < len; ++i) {
_getTextNodes(node.childNodes[i]);
}
}
}
this.each(function(i, e) {
_getTextNodes(e);
});
return textNodes;
};