Mutation Observer
<cs-mutation-observer>
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.
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 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.
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.
| Name | Description |
|---|---|
| (default) | The content to watch for mutations. |
Attributes & Properties
Learn more about attributes and properties.
| Property | Attribute | Description | Type | Default | Reflects |
|---|---|---|---|---|---|
attr | attr | Watches 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 *. | string | — | Yes |
attrOldValue | attr-old-value | Indicates whether or not the attribute's previous value should be recorded when monitoring changes. | boolean | false | Yes |
charData | char-data | Watches for changes to the character data contained within the node. | boolean | false | Yes |
charDataOldValue | char-data-old-value | Indicates whether or not the previous value of the node's text should be recorded. | boolean | false | Yes |
childList | child-list | Watches for the addition or removal of new child nodes. | boolean | false | Yes |
disabled | disabled | Disables the observer. | boolean | false | Yes |
Events
Learn more about events.
| Name | Description |
|---|---|
cs-mutation | Emitted when a mutation occurs. |

