user3433417
user3433417

Reputation: 13

If all objects have the same css value then

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

Answers (2)

n1kkou
n1kkou

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

Milind Anantwar
Milind Anantwar

Reputation: 82241

try this:

 if($('.piece').length == $('.piece').filter(function() {return $(this).css('z-index') == 0;}).length){
    // all have z-index 0
 }

Upvotes: 1

Related Questions