Ad

If Label Contains "Text" Hide Parent

- 1 answer

I'm using Shopify and I don't want to hide all of my variants but since Google Shopping Feed needs a "Color" field, I'd like to hide just the Color variant fields.

So if a label contains "Color" - if I can hide the parent then it will hide everything.

This is what I tried.

<script>

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


      </script> 

Below is the actual HTML of the area that I'd like to change.

<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>
Ad

Answer

There is no need to make a loop.

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

Also, remember that .contains is case sensitive. Another little suggestion is to use jQuery.closest instead of .parent().parent()

Ad
source: stackoverflow.com
Ad