If you control the way the changes to the element are going to happen (For example, because you provided an interface for making those changes), you should implement your own callbacks system, or just run a function whenever a change happens.
If you do not control them, you must monitor the element periodically and check for changes, either with setInterval
or recursive calls to setTimeout
. Remember to clear the interval/break the timeout loop when you no longer need to monitor for changes, or if the element becomes unavailable. If you don't, any objects being referenced from within your callback will not be garbage-collected.