Skip to content

more notes on mutation observer #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion observeAttributeChange_with_MutationObserver.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// i don't recommend actually using this code as it might slow your browser down a lot
// i recommend sparingly using this code as it could slow your browser down a lot
// see bookmarklets/preventOutlookRedDotOnBrowserTab.js
// https://caniuse.com/mutationobserver - even IE 11 has support!
// fuller example code: https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver#example

const faviconLink = document.querySelector(`link[rel~="icon"]`);

Expand Down Expand Up @@ -37,3 +39,13 @@ function observeAttributeChange(element, callback) {
attributes: true,
});
}

/*
ESSENTIALLY:

const targetNode = $('.some-thing')[0];
const config = { attributes: true }; // the other options default to false
const observer = new MutationObserver(function callback(mutationList, observer) { });
observer.observe(targetNode, config);
// observer.disconnect();
*/
Loading