0

i want to execute a function when the element 's class updated (any new class add or remove).

how i can do this in jQuery

Reporter
  • 3,776
  • 5
  • 31
  • 46
Anirudha Gupta
  • 8,670
  • 8
  • 52
  • 75

1 Answers1

2

You'll need to set up a custom event.

//function to receive event
$('#foo').bind('class_change', function() {
      alert("Class changed");
    });

//use trigger() to fire custom event
$('#foo').addClass("newClass").trigger('class_change');

$('#foo').removeClass("newClass").trigger('class_change');
Mild Fuzz
  • 27,845
  • 29
  • 97
  • 148