Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

162
Views
Detect css changes (mutationObserver on styleSheet css)

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

7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs