Reputation: 13
I'm looking for a way, in jQuery, to check if all elements with the same class (.piece) has their z-index to 0 and if so then an alert is launched. Here is what i did:
$(".piece").each(function(){
if($(this).css('z-index') != '0'){
valide=false;
}else{
valide = true;
}
});
Upvotes: 1
Views: 63
Reputation: 3142
getting the z-index
value as you've tried, will return a value of auto
. You can get the actual value with the zindex method: .zIndex()
Upvotes: 0
Reputation: 82241
try this:
if($('.piece').length == $('.piece').filter(function() {return $(this).css('z-index') == 0;}).length){
// all have z-index 0
}
Upvotes: 1