You want .textContent
in all but older IE, and .innerText
in IE (<9).
So, try:
string = (node.textContent===undefined) ? node.innerText : node.textContent;
EDIT: Or, just use GGG's much cleaner string = (node.innerText || node.textContent)
, since undefined
is falsy.