Skip to content

Instantly share code, notes, and snippets.

@trinaldi
Last active April 6, 2019 02:18
Show Gist options
  • Save trinaldi/93ab7c37798a942123e101caf38fa63d to your computer and use it in GitHub Desktop.
Save trinaldi/93ab7c37798a942123e101caf38fa63d to your computer and use it in GitHub Desktop.
Action when element exists
<div id="div1" class="select"><p>Mensagem de Sucesso</p></div>
<button id="div2" class="select"><p>Comprar algo</p></button>
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);
#div1 {
display: none;
}
@trinaldi
Copy link
Author

trinaldi commented Apr 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment