Skip to main content

sdk.watcher.watchselector

Home > @matterway/sdk > Watcher > watchSelector

Watcher.watchSelector() function

Watches an element by CSS selector, and executes code when it appears or disappears.

Signature:

export declare function watchSelector(ctx: Context, selector: string, options?: Partial<WatchSelectorOptions>): import("./watcher").Watcher<ElementHandle<Element>>;

Parameters

ParameterTypeDescription
ctxContextContext object.
selectorstringCSS selector to watch.
optionsPartial<WatchSelectorOptions>(Optional) Enter, leave callbacks and ensureVisible flag.

Returns:

import("./watcher").Watcher<ElementHandle<Element>>

Example

const watcher = watchSelector(ctx, '.selector', {
async enter: (el: ElementHandle) => {
// do something with matched el when appeared
},
async leave: (el: ElementHandle) => {
// do something with matched el when disappeared
},
});
// ...
watcher.stop()