Here's the challenge:
We have an image and text that describes it all nested in the same div. When somebody clicks on that image, we want Google Tag Manager to return that text.
Basically, we need to:
- Go up 3 parent nodes
- Go down to the child node with the class "right-section"
- Go down to the child node with the class "is-title"
- Go down to the child node with the tag "a"
- Extract the text
Using my crude, self-taught Javascript knowledge, I came up with this monstrosity of a function:
function(){
return el.parentNode.parentNode.parentNode.getElementsByClassName("right-section")[0].getElementsByClassName("is-title")[0].getElementsByTagName("a")[0].innerText;
}
... which does not work at all.
Any suggestions?
Here's what ultimately worked, for anyone Googling this: