The following function receives a parameter, which can be an array or an element, and returns the text of the element.
function text(e){
var str = "";
//If an element is passed in, get its child elements
//Otherwise, when it is an array
e=e.childNodes || e;
for ( var i = 0; i < e.length; i ) {
//Determine the element type
//If it is text, get its text, otherwise, traverse its child elements
str = e[ i].nodeType != 1 ? e[i].nodeValue : text(e[i].childNodes);
}
return str;
}