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
Parameter | Type | Description |
---|---|---|
ctx | Context | Context object. |
selector | string | CSS selector to watch. |
options | Partial<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()