Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress, Elementor: Get to a parent element of a Elementor element that I attach a class to. I wish I didn't have to do this.
function findParentTagId(childClass, parentTag) {
var element = document.querySelector(childClass);
var tag = element.tagName;
// repeat until you get to body
while (tag != 'body') {
element = element.parentElement;
if (element.tagName.toLowerCase() === parentTag.toLowerCase()) {
var dataset = element.dataset['id'];
return document.querySelector('[data-id="' + dataset + '"]');
}
tag = element.parentElement.tagName;
}
return false;
}
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.