简体   繁体   中英

How to detect when CSS value has changed?

Imagine an icon embedded in text that should be perceived as its part and behave like a letter. To achieve this it should have the same color as the text around. Finding the right color is easy in jQuery.

The problem is that the color may change. Either a script may change the CSS value, or a different value may be set in the :hover pseudoclass, and so on. In the case I've run onto it's the :hover value of a div several levels above. The text color around the icon changes, but how can I detect this event in order to adjust the icon itself?

I might be mistaken but I am sure that there is no such thing than a "change event" for CSS styles. In some modern browsers there is a DOMSubtreeModified event, but I don't think that this will even be triggered merely by changing an attribute like this.

So the only way to determine changes here would be to set an interval (window.setInterval) and check for changes every x milliseconds (choose a suitable x here).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM