Socialify

Folder ..

Viewing mutationObserver.ts
13 lines (13 loc) • 446.0 B

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
export const mutationObserver = (id: string, callbackFunction: Function) => {
    // wait for partials to load and then run callback function
    const mutationObserver = new MutationObserver(function () {
        if (document.getElementById(id)) {
            callbackFunction();
            mutationObserver.disconnect();
        }
    });
    mutationObserver.observe(document.body, {
        childList: true,
        subtree: true,
    });
}