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
});
精彩评论