dimanche 11 février 2018

jQuery - If all elements have same class

I'm looking for jQuery function that will find out when all my elements have the same class. Every few seconds one of my object will get assigned with class .found so I need to know when all objects have that class.

I have list of elements like this

<div class="objects">
  <div class="object"></div>
  <div class="object"></div>
  <div class="object"></div>
  <div class="object"></div>
  <div class="object"></div>
  <div class="object"></div>
  <div class="object"></div>
  <div class="object"></div>
</div>

So after some time, the objects would look like this

<div class="objects">
  <div class="object found"></div>
  <div class="object"></div>
  <div class="object"></div>
  <div class="object"></div>
  <div class="object found"></div>
  <div class="object"></div>
  <div class="object found"></div>
  <div class="object found"></div>
</div>

And finally once all objects have class .found I need jQuery to fire up

<div class="objects">
  <div class="object found"></div>
  <div class="object found"></div>
  <div class="object found"></div>
  <div class="object found"></div>
  <div class="object found"></div>
  <div class="object found"></div>
  <div class="object found"></div>
  <div class="object found"></div>
</div>

I've tried looking for them like this, but it won't go:

if($(".objects .object").not('.found').length) {
  alert("all done");
}




Aucun commentaire:

Enregistrer un commentaire