4
rated 0 times
[
7]
[
3]
/ answers: 1 / hits: 18895
/ 8 Years ago, sat, january 30, 2016, 12:00:00
It's not the problem to make MutationObserver work for #someID
, but what's the way to make it work for .someClass
?
Currently I'm using the following:
// this example doensn't work,
// as well as many another attempts
var target = document.querySelectorAll(.someClass);
for (var i = 0; i < target.length; i++) {
// create an observer instance
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
var foo = target[i].getAttribute(someAttribute)
if (foo == someValue)
foo.style.backgroundColor = red;
});
});
// configuration of the observer
var config = { attributes: true };
// pass in the target node, as well as the observer options
observer.observe(target, config);
}
More From » mutation-observers