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,897
  • 5
  • 33
  • 47
Anirudha Gupta
  • 9,073
  • 9
  • 54
  • 79

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
  • 29,463
  • 31
  • 100
  • 148