Seems like document.getElementsByTagName('*') could have significant performance problems depending on how complicated the DOM is. Knowing SharePoint's penchant for deeply nested tables, you could easily be in the tens of thousands of DOM elements.
Agreed. I just had that as a suggestion. A more limited set of DOM elements can (should) be passed in. But, not knowing the specific context of how someone might use this, just gave the widest-possible example. I'll edit the comment, to caution against possible performance woes.