Use childNodes rather than getElementsByTagName.

getElementsByTagName() returns all descendants, which means it iterates over children of things you have already discounted. childNodes returns only the immediate children. I think this should be more efficient (jsperf has a comparison of getElementsByTagName/childNodes where the former is 50% slower, and that's just doing a simple lookup, no iteration).