Skip to content

Instantly share code, notes, and snippets.

@waghcwb
Created June 10, 2020 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waghcwb/902d13c67c10d62d5ec66ed69ee5d5a9 to your computer and use it in GitHub Desktop.
Save waghcwb/902d13c67c10d62d5ec66ed69ee5d5a9 to your computer and use it in GitHub Desktop.
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