JS to monitor the CSS property change like "display:none"=>"display:block"?

callback, css, javascript, jquery

Solution

This is what you are looking for:

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

Problem

I want to run some JS code when an image's CSS property "display" has been changed by any other JS script/functions. Is there any method to monitor that change and setup a callback function? ``` $(this).bind.('propertychange', function(){}) ``` cannot do this, and setInterval is also a bad idea. What else could be done?

Original source

Related problems