What options are available to store a DOM ref on a DOM element, such that the ref still exists in a Mutation Observer remove callback?
In this case, the data is a DOM reference to another DOM element that needs manually removed when the observed element is removed by an external script. Because of this, I can't simply store the data in a data-*
attribute, because it is a DOM reference and not a string.
It seems that Jquery .data() properties are removed when the parent object is removed from the DOM. This makes sense, but creates a problem when the mutation observer needs to perform some type of destruct behaviour, and needs the data that was stored on the just-removed element, which is gone at the time the callback.
The elements don't have IDs, and setting them from the plug-in would defeat the unobtrusive design of the plug-in, which is why we are using mutation observers to begin with.
What options are available to store a DOM ref on a DOM element, such that the ref still exists in the Mutation Observer remove callback?