【问题标题】:If Label contains "Text" Hide Parent如果标签包含“文本”隐藏父级
【发布时间】:2018-12-29 10:00:20
【问题描述】:

我正在使用 Shopify,我不想隐藏我的所有变体,但由于 Google 购物 Feed 需要一个“颜色”字段,我想只隐藏颜色变体字段。

因此,如果标签包含“颜色” - 如果我可以隐藏父级,那么它将隐藏所有内容。

这是我尝试过的。

<script>

      $(document).ready(function() {
  if ($("label:contains('color')").size()) {
    $("label").each(function() {
      if ($(this).html() === "Color") {
        $(this).parent().parent().hide();
      }
    });
  }
});


      </script> 

以下是我要更改的区域的实际 HTML。

<div class="select">
        <label>Color</label>
        <select id="product-select-778903978076productproduct-template" name="id">

            <option selected="selected" value="8666757267548" data-sku="">Brass</option>

        </select>
      </div>

【问题讨论】:

  • 这是什么? $("label:contains('color')").size() 你应该删除它,它会起作用。

标签: jquery shopify


【解决方案1】:

无需循环。

$(document).ready(function() {
    $('label:contains("color"),label:contains("Color")').parent().parent().hide();
});

另外,请记住.contains 区分大小写。另一个小建议是使用jQuery.closest 而不是.parent().parent()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-27
    • 1970-01-01
    • 1970-01-01
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多