📜  jquery 观察类变化 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:48.457000             🧑  作者: Mango

代码示例1
var $div = $("#foo");
var observer = new MutationObserver(function(mutations) {
  mutations.forEach(function(mutation) {
    if (mutation.attributeName === "class") {
      var attributeValue = $(mutation.target).prop(mutation.attributeName);
      console.log("Class attribute changed to:", attributeValue);
    }
  });
});
observer.observe($div[0], {
  attributes: true
});

$div.addClass('red');