user237060 user237060 - 1 year ago 202
jQuery Question

jQuery - Fire event if CSS class changed

how could I fire a event if the a css class was added or changed with jQuery?
Does changing of CSS class fire the jQuery change() event?

Answer Source

Whenever you change a class in your script, you could use a trigger to raise your own event.

$(otherSelector).bind('cssClassChanged', data, function(){ do stuff });

but otherwise, no, there's no baked-in way to fire an event when a class changes. change() only fires after focus leaves an input whose input has been altered.

$(function() {
  var button = $('.clickme')
      , box = $('.box')
  button.on('click', function() { 
  $(document).on('buttonClick', function() {
.box { background-color: red; }
<script src=""></script>

<div class="box">Hi</div>
<button class="clickme">Click me</button>

More info on jQuery Triggers