Snippets Collections
    const slickTrack = document.querySelector(`.slick-track`);
    new MutationObserver((entries) => {
      entries.forEach((mutationRecord) => {
        if (photosSwipedOrButtonsCLicked) return;
        log('style has transition: ', mutationRecord.target.getAttribute('style').includes('transition'));
        if (mutationRecord.target.getAttribute('style').includes('transition')) {
          sendEvent(100322757);
          photosSwipedOrButtonsCLicked = true;
        } else {
          log('targeted mutation does not include transition style');
        }
      });
    }).observe(slickTrack, {
      attributes: true,
    }); 
// Select the node that will be observed for mutations
const targetNode = document.getElementById("some-id");

// Options for the observer (which mutations to observe)
const config = { attributes: true, childList: true, subtree: true };

// Callback function to execute when mutations are observed
const callback = (mutationList, observer) => {
  for (const mutation of mutationList) {
    if (mutation.type === "childList") {
      console.log("A child node has been added or removed.");
    } else if (mutation.type === "attributes") {
      console.log(`The ${mutation.attributeName} attribute was modified.`);
    }
  }
};

// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);

// Start observing the target node for configured mutations
observer.observe(targetNode, config);

// Later, you can stop observing
observer.disconnect();
star

Tue Apr 04 2023 19:48:17 GMT+0000 (Coordinated Universal Time)

#optimizely #mutation #observer
star

Thu Feb 23 2023 00:39:42 GMT+0000 (Coordinated Universal Time)

#mutation #observer

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension