【问题标题】:Google tag manager get closest a text谷歌标签管理器最接近文本
【发布时间】:2018-10-31 11:51:30
【问题描述】:

我想使用自定义 js 变量为事件标签 =“产品 x”获取卡片标题和商店项目标题链接的文本。

  1. 点击点击类fa-cart-plus获取标签产品x;

  2. 点击图片获取标签产品x

我在下面尝试过这个 js,但结果是 [object] [object]。

function() {
  var el = {{Click Element}};
  return $(el).closest('card-title').text('a.shop-item-title-link');
}

HTML

<div class="card card-product">     
    <div class="card-image">
        <a href="#" title="product x">
            <img width="230" height="230" src="#" class="attachment-_thumbnail" alt="product x">    
        </a>
        <div class="ripple-container"></div>
    </div>
    <div class="content">
        <h6 class="category"><a href="#">Items</a></h6>     
        <h4 class="card-title">
        <a class="shop-item-title-link" href="#" title="product x">product x</a>
        </h4>
        <div class="card-description">
            <p><span>product descirption</span></p>
        </div>
        <div class="footer">
            <div class="price">
                <h4><span class="Price"><span class="Price-currencySymbol">£</span>45.00</span></h4>
            </div>          
        <div class="stats">
            <a rel="nofollow" href="#" title="Add to cart">
                <i rel="tooltip" data-original-title="Add to cart" class="fa fa-cart-plus"></i>
            </a>            
        </div>
    </div>
</div>
</div>

【问题讨论】:

    标签: javascript google-tag-manager


    【解决方案1】:

    这是一个非常具体的目标,您要做的是将parent和sibling一起使用。

    试试这样的:

    return $(el).parents().siblings('.card-title').text();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-13
      • 1970-01-01
      • 1970-01-01
      • 2014-07-15
      • 1970-01-01
      • 1970-01-01
      • 2015-07-28
      相关资源
      最近更新 更多