After exploring a helpful Stack Overflow post, I discovered that it is feasible to monitor multiple elements using a single MutationObserver
object. In order to track the text of two specific elements on a website, I crafted 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);
To modify this script so that the Console clearly indicates which variable triggered the MutationObserver
, what changes should I make?
Update:
Upon inspecting mutation.target
, the output appears as shown in the following image:
https://i.stack.imgur.com/A1kPV.png
I am unable to differentiate whether sec
or minutes
caused the mutation. How can I enhance this distinction?