0

I want to hide divs which has attribute show-value equal to 0. Something like this:

<div class="card-tag card-product-new-tag" show-value="0">NEW</div>//this should be hidden
<div class="card-tag card-product-new-tag" show-value="1">NEW</div>//this should be visible

Html:

<div class="card-product">
     <img class="card-product-img" src="somewhere1">
     <img class="card-product-img2" src="somewhere2">
     <div class="card-tag card-product-new-tag" show-value="0">NEW</div>
     <div class="card-tag card-product-sale-tag" show-value="1">SALE</div>
     <div class="card-tag card-product-popular-tag" show-value="1">POPULAR</div>
     <div class="card-tag card-product-featured-tag" show-value="1">FEATURED</div
     <div class="card-product-name"><a href="">Product Title</a></div>
     <div class="card-product-price">99TL</div>
</div>

<div class="card-product">
     <img class="card-product-img" src="somewhere1">
     <img class="card-product-img2" src="somewhere2">
     <div class="card-tag card-product-new-tag" show-value="1">NEW</div>
     <div class="card-tag card-product-sale-tag" show-value="1">SALE</div>
     <div class="card-tag card-product-popular-tag" show-value="1">POPULAR</div>
     <div class="card-tag card-product-featured-tag" show-value="1">FEATURED</div
     <div class="card-product-name"><a href="">Product Title</a></div>
     <div class="card-product-price">99TL</div>
</div>
                

jQuery:

if ($(".card-product .card-product-new-tag").attr("show-value") == 0){
        $(".card-product .card-product-new-tag", this).hide();
    }

1 Answer 1

1

I'm Assuming that you have some common class to the elements which contains attribute show-value.

I am looping through each element and checking whether show-value attribute is 0. If value is zero, then i am hiding that particular element. For better understanding, please check the attached code snippet.

$(".card-tag").each(function(){
  if ($(this).attr('show-value') == 0) {
    $(this).hide();
  }
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<div class="card-product">
     <img class="card-product-img" src="somewhere1">
     <img class="card-product-img2" src="somewhere2">
     <div class="card-tag card-product-new-tag" show-value="0">NEW</div>
     <div class="card-tag card-product-sale-tag" show-value="1">SALE</div>
     <div class="card-tag card-product-popular-tag" show-value="1">POPULAR</div>
     <div class="card-tag card-product-featured-tag" show-value="1">FEATURED</div
     <div class="card-product-name"><a href="">Product Title</a></div>
     <div class="card-product-price">99TL</div>
</div>

<div class="card-product">
     <img class="card-product-img" src="somewhere1">
     <img class="card-product-img2" src="somewhere2">
     <div class="card-tag card-product-new-tag" show-value="1">NEW</div>
     <div class="card-tag card-product-sale-tag" show-value="1">SALE</div>
     <div class="card-tag card-product-popular-tag" show-value="1">POPULAR</div>
     <div class="card-tag card-product-featured-tag" show-value="1">FEATURED</div
     <div class="card-product-name"><a href="">Product Title</a></div>
     <div class="card-product-price">99TL</div>
</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.