Google跟踪代码管理器-获取javascript变量中元素的父级 [英] Google Tag manager - Get parent of element in a javascript variable
本文介绍了Google跟踪代码管理器-获取javascript变量中元素的父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在自定义javascript变量中,如何获取clicked元素的父元素?
In a custom javascript variable, how can you get the parent element of the clicked element?
<div>
<h2>Lorem Ipsum</h2>
<a href="#"></a>
</div>
例如,当我单击<a>
并单击<a>
以记录Lorem Ipsum时,我想获取<H2>
的内容.
For instance, I want to go get the content of the <H2>
when I click the <a>
to log Lorem Ipsum when the <a>
is clicked.
推荐答案
似乎Click Element变量在这里非常有用.太奇怪了,我在''中使用了它,这使得它仅返回url.但是您可以像这样使用它
Seems the Click Element variable works great here. It was weird, I was using it in '' and that made it return only the url. But you can use it like a this
function(){
var title = jQuery({{Click Element}}).parent().find('h2').html();
return title;
}
这篇关于Google跟踪代码管理器-获取javascript变量中元素的父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文