jQuery - 当类被删除时

jQuery - When class is removed

本文关键字:删除 jQuery      更新时间:2023-09-26

我有一个div与这个类Loading..当这个类被删除时,我只需要在jQuery中做一些事情。

我试过这个

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

谢谢!

我猜你已经删除了这个类并试图这样做。

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

否则

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

从您的评论中,我假设您的.loading类在文档就绪时被删除。

因此,请尝试以下代码,确保将其包装在$(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>

注意:在这里我使用alert您必须添加要执行的操作的脚本,或者在删除类.loading时发生。

工作 : JSFiddle