Get the closestElement

@param {node} element
@param {string} class name
770978
function getClosest(elem, selector) {
        while (elem !== document.body) {
            elem = elem.parentElement;
            var matches = typeof elem.matches == 'function' ? elem.matches(selector) : elem.msMatchesSelector(selector);

            if (matches) return elem;
        }
    }
1274322
def closest(self, tag):
        """"""

        return CSSMatch(self.selectors, tag, self.namespaces, self.flags).closest()
1120877
public static List<Element> getElementsByClass(String className) {

        return getElementsByClass(className, Tag.ALL, Document.get().getBody());
    }
548034
function(element) {
    element = $(element);
    var node = element.firstChild;
    while (node) {
      var nextNode = node.nextSibling;
      if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
        element.removeChild(node);
      node = nextNode;
    }
    return element;
  }
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)
    })
  }
1065991
function (name) {
		var wrapper,
			attribs;

		// set the class name
		if (name) {
			attribs = { 'className': PREFIX + name, 'class': PREFIX + name };
		}

		// the div to hold HTML and clipping
		wrapper = this.createElement(DIV).attr(attribs);

		return wrapper;
	}
1117088
function(element, className) {
        var re = new RegExp('(\\s|^)'+className+'(\\s|$)');
        if (re.test(element.className)) return;
        element.className += ' ' + className;
      }
925989
function getElementsByClassName(elem, name, tag) {
        if (elem.getElementsByClassName) {
            return elem.getElementsByClassName(name);
        }

        var elements = [];
        var elems = elem.getElementsByTagName(tag || '*');
        name = ' ' + name + ' ';

        each(elems, function (elem) {
            if ((' ' + (elem.className || '') + ' ').indexOf(name) >= 0) {
                elements.push(elem);
            }
        });

        return elements;
    }
1032453
function(element) {
    var textLength = this._getInnerText(element).length;
    if (textLength === 0)
      return 0;

    var linkLength = 0;

    // XXX implement _reduceNodeList?
    this._forEachNode(element.getElementsByTagName("a"), function(linkNode) {
      linkLength += this._getInnerText(linkNode).length;
    });

    return linkLength / textLength;
  }
435457
function findClosestLink( ele )    {
        while ( ele ) {
            // Look for the closest element with a nodeName of "a".
            // Note that we are checking if we have a valid nodeName
            // before attempting to access it. This is because the
            // node we get called with could have originated from within
            // an embedded SVG document where some symbol instance elements
            // don't have nodeName defined on them, or strings are of type
            // SVGAnimatedString.
            if ( ( typeof ele.nodeName === "string" ) && ele.nodeName.toLowerCase() === "a" ) {
                break;
            }
            ele = ele.parentNode;
        }
        return ele;
    }
517612
function(node, className) {
            node = Y.Dom.get(node);
            if (!node) {
                return null;
            }
            var method = function(el) { return Y.Dom.hasClass(el, className); };
            return Y.Dom.getAncestorBy(node, method);
        }
435663
function getNearestTypeElement(element) {
		var found = false;
		var moduleBoundaryReached = false;

		// We need to check for the existence of 'element' since occasionally we call this on a detached element node.
		// For example:
		//  1. event handlers like mouseout may sometimes detach nodes from the DOM
		//  2. event handlers like mouseleave will still fire on the detached node
		// Checking existence of element.parentNode ensures the element is a valid HTML Element
		while (!found && element && element.parentNode && !moduleBoundaryReached) {
			found = isTypeElement(element);
			moduleBoundaryReached = isModuleElement(element);

			if (!found) {
				element = element.parentNode;
			}

		}

		return found ? element : null;
	}
906968
public static String getClass(String element) {
        Preconditions.checkNotNull(element,"argument 'element' can not be null");
        return element.substring(element.lastIndexOf('.') + 1);
    }
1322187
def element(cls, name, parent=None, interleave=None, occur=0):
        """"""
        node = cls("element", parent, interleave=interleave)
        node.attr["name"] = name
        node.occur = occur
        return node
86352
function(el, s) { //el is the element and s the selector of the closest item to find
      // source http://gomakethings.com/climbing-up-and-down-the-dom-tree-with-vanilla-javascript/
      var f = s.charAt(0);
      for (; el && el !== document; el = el.parentNode) { // Get closest match
        if (f === '.') { // If selector is a class
          if (document.querySelector(s) !== undefined) {
            return el;
          }
        }
        if (f === '#') { // If selector is an ID
          if (el.id === s.substr(1)) {
            return el;
          }
        }
      }
      return false;
      }
734285
function closest (el, sel) {
  if (!el) return
  if (matches(el, sel)) {
    return el
  } else {
    return closest(el.parentNode, sel)
  }
}
1067601
function getSelector(node) {
  var selector = arguments.length <= 1 || arguments[1] === undefined ? [node.name] : arguments[1];

  var parent = node.parent;
  if (parent) {
    var children = parent.children;
    var matches = children.filter(function (child) {
      return child.name === node.name;
    });
    if (matches.length > 1) {
      for (var i = 0, l = matches.length; i < l; i++) {
        if (matches[i] === node) {
          selector[0] = selector[0] + ':nth-of-type(' + (i + 1) + ')';
          break;
        }
      }
    }
    selector.unshift(parent.name);
  }
  return parent && parent.parent ? getSelector(parent, selector) : selector.join(' > ');
}