3

How can I hide child div based on the attribute value of parent div. I have following markup:

<div class="offerContainer">
    <div class="Offers" producttype="CIP">
        <div class="buttons_wrap"></div>
    </div>
    <div class="Offers" producttype="P">
        <div class="buttons_wrap"></div>
    </div>
    <div class="Offers" producttype="CIP">
        <div class="buttons_wrap"></div>
    </div>
</div>

And I want to hide buttons_wrap only when atrribute value of producttype is "CIP".

Something like:

if($(obj).parents(".offersContainer").find('.Offers').attr('producttype').value == "CIP")
    $('.buttons_wrap').hide();

2 Answers 2

3
$('.buttons_wrap').each(function(){
    if($(this).parents('.Offers').attr('producttype') == "CIP"){
        $(this).hide();
    }
});

JSFIDDLE Example:

https://jsfiddle.net/Panomosh/kL11m73L/

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

2 Comments

Yes, Simple and Works!
Normally, keeping it simple is the best approach! No problem @HumaAli
0

Try This custom method

$(function() {
var $offers = $('.Offers');
$offers.each(function() {
var productType = $(this).attr('producttype');
if(productType != "CIP")
{ 
   $(this).children().hide();
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<div class="offerContainer">
    <div class="Offers" producttype="CIP">
        <div class="buttons_wrap"><button>First</button></div>
    </div>
    <div class="Offers" producttype="P">
        <div class="buttons_wrap"><button>Second</button></div>
    </div>
    <div class="Offers" producttype="CIP">
        <div class="buttons_wrap"><button>Third</button></div>
    </div>
</div>

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.