7

Any suggested implementations of a CSS property change listener? Maybe:

thread =

function getValues(){
  while(true){
    for each CSS property{
      if(properties[property] != nil && getValue(property) != properties[property]){alert('change')}
      else{properties[property] = getValue(property)}
    }
  }
}
Drew
  • 2,583
  • 5
  • 36
  • 54

2 Answers2

5

Mutation events like DOMAttrModified are deprecated. Consider using a MutationObserver instead.

Example:

<div>use devtools to change the <code>background-color</code> property of this node to <code>red</code></div>
<p>status...</p>

JS:

var observer = new MutationObserver((mutations) => {
  mutations.forEach((mutation) => {
    if (mutation.target.style.color === 'red') {
      document.querySelector('p').textContent = 'success';
    }
  });
});

var observerConfig = {
  attributes: true,
  childList: false,
  characterData: false,
  attributeOldValue: true
};

var targetNode = document.querySelector('div');
observer.observe(targetNode, observerConfig);
Kayce Basques
  • 23,849
  • 11
  • 86
  • 120
3

I think you're looking for this:

document.documentElement.addEventListener('DOMAttrModified', function(e){
  if (e.attrName === 'style') {
    console.log('prevValue: ' + e.prevValue, 'newValue: ' + e.newValue);
  }
}, false);

If you google for it, a bunch of stuff comes up. This looks promising though:

http://darcyclarke.me/development/detect-attribute-changes-with-jquery/

Swift
  • 13,118
  • 5
  • 56
  • 80