开发者

Launch an effect when element has specific class dynamically

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜