Skip to content

Instantly share code, notes, and snippets.

@vfalconi vfalconi/getParents.js
Last active Aug 29, 2015

What would you like to do?
Vanilla JavaScript replacement for jQuery's .parents() method
function getParents (el, matchSelector) {
'use strict';
var parent = el.parentNode;
if ((el.matches || el.matchesSelector || el.msMatchesSelector || el.mozMatchesSelector || el.webkitMatchesSelector || el.oMatchesSelector).call(parent, matchSelector)) {
return parent;
} else {
return getParents(parent, matchSelector);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.