开发者

Can i fire or execute a javascript function on the change of class on object?

开发者 https://www.devze.com 2023-03-16 21:02 出处:网络
i want to execute a function when开发者_C百科 the element \'s class updated (any new class add or remove).

i want to execute a function when开发者_C百科 the element 's class updated (any new class add or remove).

how i can do this in jQuery


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');
0

精彩评论

暂无评论...
验证码 换一张
取 消