在大型列表中获取元素的值

时间:2017-10-31 22:20:27

标签: javascript adobe-analytics nodelist

我已经研究过这个问题,看起来大多数答案都与检索节点列表中第一个元素的值有关,具有唯一的id或classname。

那就是说,我正在使用Adobe DTM跟踪下面示例代码中的事件。试想一下以这种方式设置的li元素页面。



<li id="af3a2eb0-cfe9-11e5-b131-6fc0b40730a0" class="theater__active__3-QdV theater__theater__nmQh3 theaterTheater">
    <div class="theaterHead theater__header__2Skwj"> 
      <div class="theater__logo__2uovm">
        <img class="" src="image" alt="logo">
      </div>
      <div class="theaterInfo theater__theaterInfo__2dTbj">
        <h3 class="theater__theaterName__1Pwxo">Arclight</h3>
        <p class="theater__theaterAddress__16_be">10000 Wilshire Boulevard, Los Angeles, CA</p>
        <span class="theater__distance__30qj2 theater__theaterAddress__16_be">4.4mi</span>
      </div>
    <div>
    </div>
   </div>
 </li>
&#13;
&#13;
&#13;  

我正在努力获得&#34; h3&#34;的价值。当点击位于其中一个父div上时,该元素。

到目前为止,我将此设置为数据元素:

&#13;
&#13;
var myNodelist = document.querySelector(".theater__theaterName__1Pwxo");
var i;
for (i = 0; i < myNodelist.length; i++) {
    return myNodelist[i].value;
}
&#13;
&#13;
&#13;

但实际上它返回一个空白值,我不确定为什么!

1 个答案:

答案 0 :(得分:1)

您可以在click事件中使用以下表达式来获取元素文本(确保将其附加到您的prop或事件规则中的evar:

%this.@text%

注意: this将引用当前点击的元素。

希望这有帮助。

相关问题