Detect css changes (mutationObserver on styleSheet css)

Viewed 256

Is there a way to detect stylesheet changes ? MutationObserver only tracks inline css changes on the element.

html

<div class="exampleClass"></div>

js

let config = {
    attributes: true,
    // attributeFilter: ["style"],
  };

  let mutationCallback = function(mutationsList) {
    mutationsList.forEach((mutation, i) => {
      console.log(mutation);
    });
  };
  let observer = new MutationObserver(mutationCallback);
  observer.observe(document.querySelector('.exampleClass'), config);

If I modify the element throught js with

document.querySelector(‘exampleClass’).style.top = '10px'

or the webconsole inspector directly on the node, the mutation observer callback is called, but if the class (not the node itself) is modified in the webconsole inspector there is no callback

0 Answers
Related