Write the shortest text getter/setter on an element for the DOM Just like jQuery's $.fn.text, write one or two functions that can get and set the text on an element.

You can't use textContent or innerText, and even less innerHTML.

Plain javascript. No DOM library. It has to work on major browsers. (No need to care about old IE.)

Shortest code wins.

Enjoy!
JavaScript (167)

function t(e,h,f){if(h||h==''){while(f=e.lastChild)e.removeChild(f);e.appendChild(document.createTextNode(h))}h=e.data||'';for(c in f=e.childNodes)h+=t(f[c]);return h}


Usage :

var textContent = t(yourElement); // get the text content
t(yourElement, ''); // clear
t(yourElement, newText); // sets a new text


Note that there is no pollution of the global namespace

Demonstration, with a multi-level DOM tree and a few tests