Parcours du dom

ES2015
Before ES2015
byTagName = (node, tagName) => {
    const found = [];
    tagName = tagName.toUpperCase();
   
   _explore = (node) => {
      for (let elt of node.childNodes) {
     
          if (elt.nodeType == document.ELEMENT_NODE)
            if (elt.nodeName == tagName)
             found.push(elt);
            _explore(elt);
      }
    }

    _explore(node);
    return found;
}
  function byTagName(node, tagName) {
    var found = [];
    tagName = tagName.toUpperCase();

    function explore(node) {
      for (var i = 0; i < node.childNodes.length; i++) {
        var child = node.childNodes[i];
        if (child.nodeType == document.ELEMENT_NODE)
          if (child.nodeName == tagName)
            found.push(child);
          explore(child);
      }
    }

    explore(node);
    return found;
  }

code fichierJS Bin on jsbin.com

Amélioration du code

code fichierJS Bin on jsbin.com