Is there a way to trigger a event in jQuery when an elements classes are changed?
Examples:
<img class="selected" />
into
<img class="selected newclass" />
triggers an event
And
<img class="selected" />
into
<img class="" />
trigger an event
You might be able to workaround on a little hacky way.
Hook.addClass() & .removeClass() like so:That way, assuming you are just interested in watching elements class changes with jQuery, you can trigger whatever code on
addingorremovingclasses. Again, just if you are using jQuery, for this example.Of course, you can
hookandoverwriteany javascript function that way.As
Nick Cravermentioned in a comment, there are several other jQuery methods which canaddorremovean elements class. You would have tohookall of those, namely:unless you know exactly which methods are called to manipulate a class, you would have to care about all of those.