开发者

Launch an effect when element has specific class dynamically

开发者 https://www.devze.com 2023-03-07 10:34 出处:网络
I want to launch an alert when a specific element has certain class, but this class is only added by another trigger after the DOM is loaded. How can i capture the moment when this specific element re

I want to launch an alert when a specific element has certain class, but this class is only added by another trigger after the DOM is loaded. How can i capture the moment when this specific element recieve his new class and launch an other event?

Ex:

    <a class="active"></a>
    <a class="">&开发者_如何学Golt;/a>
    <a class=""></a>

    Click on <div>next</div>

    |
    V

   <a class=""></a>
   <a class="active"></a>
   <a class=""></a>

   Click on <div>next</div>

   |
   V
  <a class=""></a>
  <a class=""></a>
  <a class="active"></a> -> launch an alert at this moment

Thanks!!


There is no event raised by default when an element's class is changed. It is possible to raise an event manually though, like this:

$("#element").addClass("myClass");
$("#element").trigger("classChanged");

// Somewhere else in code:

$("#element").bind("classChanged", function() {
    // do something
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号