An element has a JavaScript style object which contains the different names and values of CSS styles. I’d like to trigger a function every time this object changes without use of polling. Is there any way to do this in a way that is cross-browser compatible and would work reliably with third party code (because let’s say you’re providing a drop-in script)? Binding a JavaScript event like DOMAttrModified or DOMSubtreeModified won’t suffice because they don’t work in Chrome.
An element has a JavaScript style object which contains the different names and values
Share
Edit 4: Live Demo
Edit 3: I have put all this together as a plugin that can be downloaded from git attrchange and here is the demo page.
Edit 2:
Edit 1:
Thanks to @benvie for his feedback.
DEMO: http://jsfiddle.net/zFVyv/10/ (Tested in FF 12, Chrome 19 and IE 7.)
Ref:
Browser Support:
onpropertychange– is supported in IE (tested in IE 7)DOMAttrModified– is supported in IE 9, FF and OperaMutationObservers– is very new and it worked fine in Chrome 18. Not sure how far it is supported and yet to be tested in Safari.Thanks @benvie on adding info about WebkitMutationObserver