Firing events on CSS class changes in jQuery

后端 未结 13 1104
天涯浪人
天涯浪人 2020-11-22 04:45

How can I fire an event if a CSS class is added or changed using jQuery? Does changing of a CSS class fire the jQuery change() event?

13条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 05:03

    You can bind the DOMSubtreeModified event. I add an example here:

    HTML

    sjdfhksfh

    JavaScript

    $(document).ready(function() {
      $('#changeClass').click(function() {
        $('#mutable').addClass("red");
      });
    
      $('#mutable').bind('DOMSubtreeModified', function(e) {
          alert('class changed');
      });
    });
    

    http://jsfiddle.net/hnCxK/13/

提交回复
热议问题