'Specify which element triggered MutationObserver on multiple elements
With the help of the following SO-post. I know it is possible to track multiple elements with a single MutationObserver-object. I want to track the text of two elements on a website, so I write the following script:
var seconds = document.getElementsByClassName('sr-lmt-0-ms-countdown__time srt-primary-7 srm-large')[2];
var minutes = document.getElementsByClassName('sr-lmt-0-ms-countdown__time srt-primary-7 srm-large')[3];
var callback = function(mutations) {
for (var mutation of mutations) {
// do something
// console.log(mutation + (minutes or seconds));
}
};
var observer = new MutationObserver(callback);
var config = {characterData: true, subtree: true};
observer.observe(minutes, config);
observer.observe(seconds, config);
How can I alter this script so the Console shows which variable triggered the MutationObserver?
Edit
If I inspect mutation.target I see the following:
I don't see whether sec or minutes triggered the mutation? How can I make this distinguishing?
Solution 1:[1]
let observer = new MutationObserver(mutationRecords => {
console.log(mutationRecords); // console.log(the changes)
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user2962010 |

