Last active
          April 6, 2019 02:18 
        
      - 
      
- 
        Save trinaldi/93ab7c37798a942123e101caf38fa63d to your computer and use it in GitHub Desktop. 
    Action when element exists
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <div id="div1" class="select"><p>Mensagem de Sucesso</p></div> | |
| <button id="div2" class="select"><p>Comprar algo</p></button> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var div1 = document.getElementById("div1"); | |
| var div2 = document.getElementById("div2"); | |
| window.dataLayer = []; | |
| var makeExists = function(el){ | |
| el.onclick = function(){ | |
| div1.style.display = "block"; | |
| }; | |
| } | |
| makeExists(div2); | |
| var observer = new MutationObserver(function(mutations) { | |
| mutations.forEach(function(mutation) { | |
| if(mutation.attributeName === 'style'){ | |
| dataLayer.push("Deu pra entender") | |
| console.log(dataLayer); | |
| } | |
| }); | |
| }); | |
| // Notify me of style changes | |
| var observerConfig = { | |
| attributes: true, | |
| attributeFilter: ["style"] | |
| }; | |
| observer.observe(div1, observerConfig); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #div1 { | |
| display: none; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Simple POC