Skip to content

Instantly share code, notes, and snippets.

@allex
Created April 28, 2012 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save allex/2515452 to your computer and use it in GitHub Desktop.
Save allex/2515452 to your computer and use it in GitHub Desktop.
getElementsByTagName
/* vim: set ft=javascript: */
// http://dean.edwards.name/weblog/2009/12/getelementsbytagname/
function getElementsByTagName(node, tagName) {
var elements = [], i = 0, anyTag = tagName === "*", next = node.firstChild;
while ((node = next)) {
if (anyTag ? node.nodeType === 1 : node.nodeName === tagName) elements[i++] = node;
next = node.firstChild || node.nextSibling;
while (!next && (node = node.parentNode)) next = node.nextSibling;
}
return elements;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment