Cleaner way to implement document.getElementsByTagName()