Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Mutation on Shopify Customizer

Mutation on Shopify Customizer

mjbalutan1
Shopify Partner
5 0 0

The code below doesn't work when the customizer is fully loaded. The goal of this code is to check for changes within the section, so that I could run functions on it.

if (Shopify.designMode) {
  document.addEventListener('DOMContentLoaded', function(){
    const targetNode = document.getElementById("#shopify-section-{{ section.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);
  });
}

 

Replies 0 (0)