Answers for "jquery observe class change"

0

jquery observe class change

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');
Posted by: Guest on April-01-2021

Code answers related to "jquery observe class change"

Code answers related to "Javascript"

Browse Popular Code Answers by Language