What I want to do is have a "live" function that monitors the existance of a classname, and if any event causes that classname to be added anywhere in the DOM, another function will be fired.
How do I write a function that does that?
What I want to do is have a "live" function that monitors the existance of a classname, and if any event causes that classname to be added anywhere in the DOM, another function will be fired.
How do I write a function that does that?
This kind of functionality does not exist in jQuery and will not be added because the methods required to implement it are depreciated by browsers. Source: https://forum.jquery.com/topic/a-global-event-or-simple-callback-for-new-content-entering-the-page-specifically-for-applying-widgets-and-behaviour#14737000003041291
However, on that same post, there's mention of a plugin that does this.
You have two options for listening for a classname.
Other than that, there is no way of 'hooking into' another element very easily. In theory, if they have not wrapper their code in a closure, you could do the following:
var _theirfunction = theirfunction;
function theirfunction () {
// You function to override theirs
_theirfunciton(); // Run their code. Make sure to pass along the arguments
yourFunction();
}
Though when they update it, you would need to make sure the parameters match, and the function name is the same. This is also subject to issues depending on how they handle their function and how it is called. You would need to do an apply
if this is within a specific context.