<cs-mutation-observer>
StableHelpersSince 0.1

Mutation observers watch for changes to an element's DOM tree and emit an event when they occur. Provides a thin, declarative interface to the browser's MutationObserver API.

Click to mutate

The observer saw the variant change to brand.

The mutation observer will report changes to the content it wraps through the cs-mutation event. When emitted, event.detail.mutationList holds a collection of MutationRecord objects describing how it changed.

Specify at least one of attr, child-list, or char-data.
These attributes tell the observer what changes to watch. Without at least one, no cs-mutation events are emitted.

Examples

Child List

Use the child-list attribute to watch for new child elements that are added or removed.

Add button

Add buttons, then click a numbered one to remove it. The observer saw no changes yet.

API

Importing

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick this component, use one of the following snippets.

npm Self-Hosted React
import '@cruglobal/cornerstone-components/components/mutation-observer/mutation-observer.js';
import './cornerstone/components/mutation-observer/mutation-observer.js';
import CsMutationObserver from '@cruglobal/cornerstone-components/react/mutation-observer/index.js';

Slots

Learn more about using slots.

NameDescription
(default)The content to watch for mutations.

Attributes & Properties

Learn more about attributes and properties.

PropertyAttributeDescriptionTypeDefaultReflects
attrattrWatches for changes to attributes. To watch only specific attributes, separate them by a space, e.g. attr="class id title". To watch all attributes, use *.stringYes
attrOldValueattr-old-valueIndicates whether or not the attribute's previous value should be recorded when monitoring changes.booleanfalseYes
charDatachar-dataWatches for changes to the character data contained within the node.booleanfalseYes
charDataOldValuechar-data-old-valueIndicates whether or not the previous value of the node's text should be recorded.booleanfalseYes
childListchild-listWatches for the addition or removal of new child nodes.booleanfalseYes
disableddisabledDisables the observer.booleanfalseYes

Events

Learn more about events.

NameDescription
cs-mutationEmitted when a mutation occurs.