Skip to content Skip to sidebar Skip to footer

How Can I Detect When An Html Element’s Class Changes?

text How do I detect when e.g. a .live class is added to this
and do something when it happened? Fo

Solution 1:

There are DOM events, but they are far from perfect and not available in most browsers. In other words: Not possible (reliably). There are hacks like intervals and checking it in each iteration, but if you need to do something like this, your design is probably screwed. Keep in mind that such things will be slow and that there will always be a delay. The smaller the delay, the slower the application. Do not do that.

Solution 2:

You may checkout the following article for some ideas.

Solution 3:

I don't know if the class you add to the link is always the same but if so, why don't you use CSS for this.

<style type='text/css>
  .myaddedclass{display:none}
</style>

Solution 4:

If you just need to figure this out once (i.e. not in code), Google Chrome’s web inspector shows DOM changes live. Not sure if that’d help your situation out though.

Post a Comment for "How Can I Detect When An Html Element’s Class Changes?"