Created
November 19, 2018 15:28
-
-
Save ShuvoHabib/6a21ed0f8fd3de737bf3c06813e67824 to your computer and use it in GitHub Desktop.
Mutation Observer
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 targetNode = document.querySelectorAll('.validation-message'), i; | |
// Options for the observer (which mutations to observe) | |
var config = { attributes: true, childList: true, subtree: true }; | |
var callback = function(mutationsList, observer) { | |
for(var mutation of mutationsList) { | |
if (mutation.type == 'childList') { | |
//console.log('mutation.nextElementSibling', mutation.target.nextElementSibling.nextElementSibling); | |
if(mutation.target.childNodes[0] && mutation.target.childNodes[0].length != 29){ | |
if(mutation.target.nextElementSibling.className == "screen-reader"){ | |
mutation.target.nextElementSibling.style.opacity = "0"; | |
} else { | |
mutation.target.nextElementSibling.nextElementSibling.style.opacity = "0"; | |
} | |
} else { | |
if(mutation.target.nextElementSibling.className == "screen-reader"){ | |
mutation.target.nextElementSibling.style.opacity = "1"; | |
} else { | |
mutation.target.nextElementSibling.nextElementSibling.style.opacity = "1"; | |
} | |
console.log('mutation False', mutation.target.childNodes[0].length); | |
} | |
} | |
} | |
}; | |
var observer = new MutationObserver(callback); | |
for (i = 0; i < targetNode.length; ++i) { | |
observer.observe(targetNode[i], config); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment