I would like to use a MutationObserver
object to observe changes to some of my DOM nodes.
The docs give an example of creating a MutationObserver
object and registering it on a target.
// select the target node
var target = document.querySelector('#some-id');
// create an observer instance
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.log(mutation.type);
});
});
// configuration of the observer:
var config = { attributes: true, childList: true, characterData: true };
// pass in the target node, as well as the observer options
observer.observe(target, config);
Say I have the code above, but just under it, I place this code:
var target2 = document.querySelector('#some-other-id');
var config2 = {attributes: true, subtree: true};
observer.observe(target2, config2);
Will observer
:
- now be observing 2 targets?
- will it stop observing
target
? - will it decide not to observe
target2
? - will it throw an error?
- or will it exhibit some other behavior?