Bluga
Bluga

Reputation: 39

jQuery - When class is removed

I've a div with this class Loading .. I just need to do something in jQuery when this class is removed.

I have try this

$(".class").not('loading').each(function(){

  // do something

});

Thanks!

Upvotes: 1

Views: 1342

Answers (2)

Sumit Sahay
Sumit Sahay

Reputation: 514

I am guessing you have already removed the class and trying to do this.

$(".class").not('.loading').each(function(){
  // do something
});

Otherwise,

if(!$('.class').hasClass('loading')){
//Do something
}

Upvotes: 1

divy3993
divy3993

Reputation: 5810

From your comments i assume that your .loading class is removed on document ready.

So try this following code make sure to wrap it in $(document).ready(function(){..........});

$(document).ready(function(){
  $(".demo").removeClass("loading"); // Remove this line and check again you will understand the difference

  if(!$(".demo").hasClass("loading"))
  {
  	alert("Loading Class is Removed!");
  }  
});
.demo
{
  color:green;
}

.loading
{
  color:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="demo loading">
  This is loading class
</div>

Note: Here where i am using alert you must add your script of what you want to do, or make happen on remove of class .loading.

Working : JSFiddle

Upvotes: 0

Related Questions