Created
March 9, 2019 23:44
-
-
Save yayMark/3065529f22855fc317ca652bc717bee2 to your computer and use it in GitHub Desktop.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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