find the first node with the given tagName, starting from the node the event was triggered on; traverses the DOM upwards
177728
function(event, tagName) {
    var element = Event.element(event);
    while (element.parentNode && (!element.tagName ||
        (element.tagName.toUpperCase() != tagName.toUpperCase())))
      element = element.parentNode;
    return element;
  }
798104
function getDOMPath(node, dontGoUpTheDom /* = false */ ) {
		var path = [],
			entry = '';

		if (node === window) {
			return 'window';
		}

		while (node instanceof Node) {
			// div
			entry = node.nodeName.toLowerCase();

			// shorten the path a bit
			if (['body', 'head', 'html'].indexOf(entry) > -1) {
				path.push(entry);
				break;
			}

			if (node instanceof DocumentFragment) {
				entry = 'DocumentFragment';
			}

			// div#foo
			if (node.id && node.id !== '') {
				entry += '#' + node.id;
			}
			// div#foo.bar.test
			else if (typeof node.className === 'string' && node.className !== '') {
				entry += '.' + node.className.trim().replace(/\s+/g, '.');
			}
			// div[0] <- index of child node
			else if (node.parentNode instanceof Node) {
				entry += '[' + Math.max(0, Array.prototype.indexOf.call(node.parentNode.children || node.parentNode.childNodes, node)) + ']';
			}

			path.push(entry);

			if (dontGoUpTheDom === true) {
				break;
			}

			// go up the DOM
			node = node && node.parentNode;
		}

		return (path.length > 0) ? path.reverse().join(' > ') : false;
	}
447502
function getTag(dom) {
  return dom.tagName && __TAG_IMPL[getAttr(dom, IS_DIRECTIVE) ||
    getAttr(dom, IS_DIRECTIVE) || dom.tagName.toLowerCase()]
}
703934
function(element, selector, event, callback, capturePhase) {
    const delegateElement = $(element).array[0]
    $(element).forEach(function(ctx) {
      $(ctx).on(event, function(e) {
        let target = e.target
        if (e.target.nodeType === 3) {
          target = e.target.parentNode
        }
        $(ctx).find(selector).forEach(function(delegateElement) {
          if (delegateElement === target) {
            callback.call(delegateElement, e)
          } else {
            try {
              const ancestor = $(target).closest(selector)
              if (delegateElement === ancestor.array[0]) {
                callback.call(delegateElement, e)
              }
            } catch (err) {}
          }
        })
      }, capturePhase)
    })
  }
281077
function getTag(entry, tagName) {
  var parsed = entry.parsed;
  return _.find(parsed.tags, ['title', tagName]) || null;
}
278075
def startElement(self, node):
        """"""
        if node is None:
            return

        if self.__filter_location is not None:
            # dont even parse includes.
            # FIXME: go back on dependencies ?
            if node.location.file is None:
                return
            elif node.location.file.name not in self.__filter_location:
                return
        # find and call the handler for this element
        log.debug(
            '%s:%d: Found a %s|%s|%s',
            node.location.file,
            node.location.line,
            node.kind.name,
            node.displayname,
            node.spelling)
        # build stuff.
        try:
            stop_recurse = self.parse_cursor(node)
            # Signature of parse_cursor is:
            # if the fn returns True, do not recurse into children.
            # anything else will be ignored.
            if stop_recurse is not False:  # True:
                return
            # if fn returns something, if this element has children, treat
            # them.
            for child in node.get_children():
                self.startElement(child)
        except InvalidDefinitionError:
            # if the definition is invalid
            pass
        # startElement returns None.
        return None
262313
function tag(node, tagName){
    var element = get(node) || document;

    if (tagName == '*' && element.all)
      return arrayFrom(element.all);
    else
      return arrayFrom(element.getElementsByTagName(tagName || '*'));
  }
673615
function findFirstTextNode(node) {
          var walker;

          if (node) {
            walker = new TreeWalker(node, node);

            for (node = walker.current(); node; node = walker.next()) {
              if (node.nodeType === 3) {
                return node;
              }
            }
          }
        }
268094
function getSelectorList(eventName){
  if (hasOwnProperty.call(eventMap, eventName))
    return eventMap[eventName];

  var selectorList = eventMap[eventName] = [];
  var inputTimeout = null;

  switch (eventName) {
    case SHOW_EVENT:
      selectorList.visible = {};
      setInterval(checkShow, VISIBLE_CHECK_INTERVAL);
      break;

    default:
      eventUtils.addGlobalHandler(eventName, function(event){
        var path = event.path.reduce(function(res, node){
          var role = node.getAttribute ? node.getAttribute('role-marker') : null;
          if (role)
            res.unshift(parseRole(role));
          return res;
        }, []);

        // if there is at least one `role-marker` attribute in the DOM [x]path for the clicked (or hovered or `event`ed) element
        // then lets search a matching selector in our loaded track map
        if (path.length)
          selectorList.forEach(function(item){
            var result = handleEventFor(path, item, event);
            if (result)
              if (result.debounce)
              {
                clearTimeout(inputTimeout);
                inputTimeout = setTimeout(function(){
                  track(result.dataToTrack);
                }, INPUT_DEBOUNCE_TIMEOUT);
              }
              else
              {
                track(result.dataToTrack);
              }
          });
      });
  }

  return selectorList;
}
764563
public function findFirstTag($tagName)
    {
        $nodes = $this->findTags($tagName);

        return $nodes->length > 0 ? $nodes->item(0) : false;
    }
815838
def first_element
      check_section!('first_element')
      range = dom_nodes
      nodes = `range.startContainer.childNodes`

      start_index = `range.startOffset`
      end_index = `range.endOffset`

      start_index.upto(end_index) do |index|
        node = `nodes[index]`

        # Return if an element
        if `node.nodeType === 1`
          return node
        end
      end

      return nil
    end
953564
function domIndexOf(nodes, domNode) {
      var index = -1;

      for (var i = 0; i < nodes.length; i++) {
        var node = nodes[i];

        if (node.type !== 'TextNode' && node.type !== 'ElementNode') {
          continue;
        } else {
          index++;
        }

        if (node === domNode) {
          return index;
        }
      }

      return -1;
    }
31400
def next_element(element, name = nil)
      if siblings = element.parent.children
        found = false
        siblings.each do |node|
          if node.equal?(element)
            found = true
          elsif found && node.tag?
            return node if (name.nil? || node.name == name)
          end
        end
      end
      nil
    end
262772
function(ast, offset) {
			var found = null;
			var dom = ast;
			var missingTagClose = false;
			if (!Array.isArray(ast) && ast.children){
				dom = ast.children;
			}
			 Visitor.visit(dom, {
	            visitNode: function(node) {
					if(node.range[0] <= offset) {
						found = node;
					} else {
					    return Visitor.BREAK;
					}      
	            },
	            endVisitNode: function(node) {
	            	if(found && !missingTagClose && offset >= found.range[1] && offset > node.range[0]) {
	            		found = node;
	            		// If at the boundary of a tag range and there is a missing end tag, return the innermost tag  <a><b></a>
	            		if (offset === found.range[1] && found.endrange && found.openrange && found.endrange[1] === found.openrange[1]){
	            			missingTagClose = true;
	            		}
	            	}
	            }
	        });
	        return found;
		}
746762
def getnodes(self, name):
        "'"
        for node in self.nodes:
            if striptag(node.tag) == name:
                yield node
1083131
def parse_Element(self, node):
        
        name = node.tagName
        ignores = self.ignores
        if name in ignores:
            return
        attr = "do_%s" % name
        if hasattr(self, attr):
            handlerMethod = getattr(self, attr)
            handlerMethod(node)
        else:
            self.generic_parse(node)
665278
def first_child_found_in(self, *tagnames):
        
        for tagname in tagnames:
            child = self.find(qn(tagname))
            if child is not None:
                return child
        return None