Let me illustrate my question: I have an external JavaScript library that creates certain HTML elements for me dynamically based on user input and interaction, and I'm looking to write a script that would automatically add a certain class to these dynamically created elements. Assume that I also am unable to edit the external JavaScript library I'm using.
Is this elegantly possible? If so, how? If not, could this be a side-effect of poor implementation design?
I've thought about somehow monitoring the DOM to see when it was updated, and adding the classes to these new elements then, but this seems cumbersome and possibly unnecessary.
Thanks in advance for any thoughts / solutions!
Edit:
As requested, here's a simplified example of what I'm trying to accomplish with a code sample:
// function in external library, assume it cannot be edited!
function addElement() {
$('body').append($('<div class="newly_created_element"></div>'));
}
// my code, looking to add the class name to the newly-created elements
// from the external function above...
// pseudo-coded as I have no idea how to do this!
$(function(){
when (new element added) {
add class "my_own_class";
}
});
I hope this makes sense!