Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
if (!Element.prototype.findParentTagName) {
Element.prototype.findParentTagName = function (stringData) {
try {
if (this.tagName.equal(stringData)) return this;
let parent = this.parentElement;
while (parent) {
if (parent.tagName.equal(stringData)) return parent;
parent = parent.parentElement;
}
} catch (e) {
return null;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment