GuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityLog In

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

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.