Reputation: 91
i have three divs with class UserDetail. if a div doesnot contain div.info
then have to hide that div.UserDetail
Update from comment:
I have tried this:
var childInfo=$('div.UserDetail').find("div.info").size();
if(childInfo==0) $('div.UserDetail').hide();
This is not working as all the divs contains same class name and other two divs have the child div class=info
Upvotes: 1
Views: 1524
Reputation: 1592
HTML
<div class="userDetails">1</div>
<div class="userDetails">2<div class="info"></div></div>
<div class="userDetails">3</div>
JS
$.each( $( "div.userDetails" ), function( i, div ) {
if ( $( div ).find( "div.info" ).length == 0 ) {
$( div ).hide();
}
} );
Upvotes: 0
Reputation: 575
$(".UserDetail").each(function (index) {
if ( $(this).find('div.info').length < 0) {
$(this).hide();
}
});
Upvotes: -1
Reputation: 354
I think this might work
$.each($('div.UserDetail'), function(i, value){
if($(value).find('div.info').length == 0)
{
$(value).hide();
}
});
Upvotes: 1
Reputation: 93561
Use :has
with :not
selector:
$('.UserDetail:not(:has(.info))').hide()
or in full (if you care about the divs): http://jsfiddle.net/TrueBlueAussie/5pbap/1/
$('div.UserDetail:not(:has(div.info))').hide()
Upvotes: 1