After digging into MutationObserver, it seems the best overall method of adding custom classes to shapediver-domElements. I can just create an observer and know that my classes will be added without having to use a callback every time the viewer updates shapediver-domElements.
In light of this, the topic title is probably irrelevant.
For my usage scenario (applying a class based on 2D text tags being a number or not), I’m using this to moot my issue:
const config = {childList: true, subtree: true};
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if( mutation.addedNodes.length > 0
&& mutation.addedNodes[0].classList.contains("shapediver-domElement-span")
) {
return (
Number(mutation.addedNodes[0].innerHTML)
? mutation.target.classList.add("numbers")
: mutation.target.classList.add("not-numbers")
);
}
});
});
const target = document.querySelector(".shapediver-domElements");
observer.observe(target, config);