I use this as 1 of the many parts in my language translation jquery script.
This part grab's the text of a node, as I loop through all the nodes on a web page.
However it grab's a lot of the hidden javascript as a text node as well.
So is there a way to modify this, to just get the html side? And plus trim unneeded whitespace?
Here is the original code.
var content = function (node, txt) {
if (txt) {
if (node.textContent) {
node.textContent = txt;
} else if (node.nodeValue) {
node.nodeValue = txt;
}
} else {
return node.textContent ? node.textContent : node.nodeValue;
}
};
Here will help show the context of this code.
// recursive tree walker
(function (parent) {
var childs = parent.childNodes;
// if childs object has data
if (childs && childs.length) {
var i = childs.length; while (i--) {
// assign node variable to childs object
node = childs[i];
// text node found, do the replacement
if (node.nodeType == 3) {
// assign the current value to a variable
var value = content(node);
} else {
arguments.callee(node);
}
}
}
})(document.body);
All of this is the logic my language translation code works, I just want to tweak the input so it grabs the text but no javascript code that is in the source of the page.