Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mutationobserver-shim

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mutationobserver-shim

MutationObserver shim for ES3 environments

  • 0.2.7
  • npm
  • Socket score

Version published
Weekly downloads
200K
decreased by-34.86%
Maintainers
1
Weekly downloads
 
Created

What is mutationobserver-shim?

The mutationobserver-shim package is a polyfill for the MutationObserver API, which allows you to watch for changes being made to the DOM tree. This is particularly useful for environments where the native MutationObserver is not available.

What are mutationobserver-shim's main functionalities?

Observing attribute changes

This feature allows you to observe changes to attributes of a DOM element. The provided code sample sets up a MutationObserver to watch for attribute changes on an element with the ID 'some-id'.

const targetNode = document.getElementById('some-id');
const config = { attributes: true };
const callback = function(mutationsList, observer) {
  for(let mutation of mutationsList) {
    if (mutation.type === 'attributes') {
      console.log('The ' + mutation.attributeName + ' attribute was modified.');
    }
  }
};
const observer = new MutationObserver(callback);
observer.observe(targetNode, config);

Observing child list changes

This feature allows you to observe changes to the child nodes of a DOM element. The provided code sample sets up a MutationObserver to watch for additions or removals of child nodes on an element with the ID 'some-id'.

const targetNode = document.getElementById('some-id');
const config = { childList: true };
const callback = function(mutationsList, observer) {
  for(let mutation of mutationsList) {
    if (mutation.type === 'childList') {
      console.log('A child node has been added or removed.');
    }
  }
};
const observer = new MutationObserver(callback);
observer.observe(targetNode, config);

Observing subtree changes

This feature allows you to observe changes to the entire subtree of a DOM element. The provided code sample sets up a MutationObserver to watch for additions or removals of child nodes within the subtree of an element with the ID 'some-id'.

const targetNode = document.getElementById('some-id');
const config = { subtree: true, childList: true };
const callback = function(mutationsList, observer) {
  for(let mutation of mutationsList) {
    if (mutation.type === 'childList') {
      console.log('A child node has been added or removed in the subtree.');
    }
  }
};
const observer = new MutationObserver(callback);
observer.observe(targetNode, config);

Other packages similar to mutationobserver-shim

Keywords

FAQs

Package last updated on 09 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc