---
title: observeSelector
slug: performance-edge/api/observeselector
docTags: 
createdAt: 2026-06-23T07:48:06.378Z
---

Register a callback that fires when an element is added to the DOM.

```javascript
let unobserve = window.optimizelyEdge.get("utils").observeSelector("#cta", function(ctaElement) {
  ctaElement.innerText = "Click me!";
  unobserve();
});
```

## Parameters

| Parameter               | Type     | Description                                                                                                                                                |
| ----------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **selector** *required* | string   | A CSS selector indicating the element to wait for.                                                                                                         |
| **callback** *required* | function | The function that will be executed each time an element is added to the DOM that matches the selector. The first argument is the exact node that is added. |

## Returns

| Parameter     | Type     | Description                                        |
| ------------- | -------- | -------------------------------------------------- |
| **unobserve** | function | A function that can be executed to stop observing. |

